phoenixx Posted April 22, 2010 Share Posted April 22, 2010 Just wondering if anyone knows which method I should use for the following issue: I'm scraping a page (in this case a craigslist ad) and trying to get the content between these two tags: <div id="userbody"> and <!-- START CLTAGS --> . I'm using a regex that isn't returning anything, but would it be cleaner just to explode or strpos the string? Here's the code I'm using: $data = @file_get_contents('http://houston.craigslist.org/fud/1704346680.html'); preg_match('/class="userbody">([^"]*)<!-- START CLTAGS -->/is',$data,$resultscontent); echo $resultscontent[1]; Thanks in advance for your help. Link to comment https://forums.phpfreaks.com/topic/199399-explode-strpos-or-regex/ Share on other sites More sharing options...
JAY6390 Posted April 22, 2010 Share Posted April 22, 2010 The regex isn't working because you are using class=" instead of id=" since it's the div id you are trying to match Link to comment https://forums.phpfreaks.com/topic/199399-explode-strpos-or-regex/#findComment-1046501 Share on other sites More sharing options...
phoenixx Posted April 22, 2010 Author Share Posted April 22, 2010 A typo - the data is id="userbody" but even changing that doesn't work. Link to comment https://forums.phpfreaks.com/topic/199399-explode-strpos-or-regex/#findComment-1046533 Share on other sites More sharing options...
JAY6390 Posted April 22, 2010 Share Posted April 22, 2010 $data = file_get_contents('http://houston.craigslist.org/fud/1704346680.html'); preg_match('/id="userbody">(.*?)<!-- START CLTAGS -->/is',$data,$resultscontent); echo $resultscontent[1]; Link to comment https://forums.phpfreaks.com/topic/199399-explode-strpos-or-regex/#findComment-1046534 Share on other sites More sharing options...
phoenixx Posted April 22, 2010 Author Share Posted April 22, 2010 PERFECT!!!! Many Thanks! Link to comment https://forums.phpfreaks.com/topic/199399-explode-strpos-or-regex/#findComment-1046551 Share on other sites More sharing options...
JAY6390 Posted April 22, 2010 Share Posted April 22, 2010 No problem Link to comment https://forums.phpfreaks.com/topic/199399-explode-strpos-or-regex/#findComment-1046552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.