Jump to content

Help with cURL


GamerGun

Recommended Posts

Dear,

 

Currently i'm having the following code:

 

<?php

$userAgent = ‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)’;

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.weeronline.nl/Go/GenericPages/WeatherSynopsis?synopsisCategory=WeatherForecastHayfeverExpectations');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, true);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl_handle, CURLOPT_AUTOREFERER, true);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 10);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

    print $buffer;
?>

 

This does show the content from http://www.weeronline.nl/Go/GenericPages/WeatherSynopsis?synopsisCategory=WeatherForecastHayfeverExpectations

 

Though, the only part i want is from:

 

<h1>

In het westen redelijk veel pollen

    </h1>

 

'till

 

<p class="author">

Auteur: Marie-Jette Wierbos - 17 mei 2010 - 02:00

 

</p>

 

This, and everything in between, does change every day. So basically i want the text (no images and such) from the <h1> 'till the </p>

 

Any idea how? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/202030-help-with-curl/
Share on other sites

Thanks, it works so far

 

<?php

$userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.weeronline.nl/Go/GenericPages/WeatherSynopsis?synopsisCategory=WeatherForecastHayfeverExpectations');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, true);
curl_setopt($curl_handle, CURLOPT_AUTOREFERER, true);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 10);
$result = curl_exec($curl_handle);
curl_close($curl_handle);

preg_match_all('%<p>(.*?)</p>%', $result, $match, PREG_PATTERN_ORDER);
$match = $match[1];
foreach($match as $matches){
  echo "$matches<br /><br />";
}

?>

 

I just don't get it to work with the h1 tags, when i replace <p> with <h1> and </p> with </h1> it outputs nothing...

 

Any idea? Thx

Link to comment
https://forums.phpfreaks.com/topic/202030-help-with-curl/#findComment-1059907
Share on other sites

Got it!

 

<?php

$userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.weeronline.nl/Go/GenericPages/WeatherSynopsis?synopsisCategory=WeatherForecastHayfeverExpectations');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, true);
curl_setopt($curl_handle, CURLOPT_AUTOREFERER, true);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 10);
$result = curl_exec($curl_handle);
curl_close($curl_handle);

preg_match_all('=<h1[^>]*>(.*)</h1>=siU', $result, $match, PREG_PATTERN_ORDER);
$match = $match[1];
foreach($match as $matches){
  echo "<h2>$matches</h2>";
}

preg_match_all('%<p>(.*?)</p>%', $result, $match, PREG_PATTERN_ORDER);
$match = $match[1];
foreach($match as $matches){
  echo "$matches<br /><br />";
}

?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/202030-help-with-curl/#findComment-1059910
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.