GamerGun Posted May 17, 2010 Share Posted May 17, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/202030-help-with-curl/ Share on other sites More sharing options...
MadTechie Posted May 17, 2010 Share Posted May 17, 2010 Any idea how? Thanks! You may want to look at preg_match or strpos substr Quote Link to comment https://forums.phpfreaks.com/topic/202030-help-with-curl/#findComment-1059553 Share on other sites More sharing options...
GamerGun Posted May 18, 2010 Author Share Posted May 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/202030-help-with-curl/#findComment-1059907 Share on other sites More sharing options...
GamerGun Posted May 18, 2010 Author Share Posted May 18, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/202030-help-with-curl/#findComment-1059910 Share on other sites More sharing options...
katierosy Posted May 18, 2010 Share Posted May 18, 2010 You may read and understand well regular expressions * ? \s \t . along with these methods preg_match_all function or preg_match in php. Please see http://simplehtmldom.sourceforge.net/ , you may want to read regular expressions latter. If you are clear on foreach in php Quote Link to comment https://forums.phpfreaks.com/topic/202030-help-with-curl/#findComment-1060033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.