Modernvox Posted January 8, 2010 Share Posted January 8, 2010 Can I limit the number of records returned from a scraping session? <?php $st = isset($_POST['submit']) ? $_POST['state'] : ''; $urls = array(); if ($st == "AL") { $urls = array("http://auburn.craigslist.org", "http://bham.craigslist.org"); } else if ($st == "AK") { $urls= array("http://anchorage.craigslist.org"); } else if ($st == "AZ") { $urls = array("http://anchorage.craigslist.org"); } foreach ($urls as $url) { $html = file_get_contents("$url/muc/"); preg_match_all('/<a href="([^"]+)">([^<]+)<\/a><font size="-1">([^"]+)<\/font>/s', $html,$posts,PREG_SET_ORDER); //echo "<pre>";print_r($posts); foreach ($posts as $post) { //print $post[0]; //HTML $post[2] = str_ireplace($url,"",$post[2]); //remove domain echo "<a href=\"$url{$post[1]}\">{$post[2]}<font size=\"3\">{$post[3]}<br />"; print "<BR />\n"; } } ?> Thanks in Advance Link to comment https://forums.phpfreaks.com/topic/187739-limit-the-of-records-returned-from-a-scraping-session/ Share on other sites More sharing options...
Modernvox Posted January 8, 2010 Author Share Posted January 8, 2010 Can someone provide a yes or no to this? Thanks Guyz Link to comment https://forums.phpfreaks.com/topic/187739-limit-the-of-records-returned-from-a-scraping-session/#findComment-991199 Share on other sites More sharing options...
mrMarcus Posted January 8, 2010 Share Posted January 8, 2010 yes. <?php $i = 1; //set start point; $limit = 5; //set limit; foreach ($posts as $post) { //print $post[0]; //HTML $post[2] = str_ireplace($url,"",$post[2]); //remove domain echo "<a href=\"$url{$post[1]}\">{$post[2]}<font size=\"3\">{$post[3]}<br />"; print "<BR />\n"; if ($i == $limit) { break; } $i++; } ?> something like that. Link to comment https://forums.phpfreaks.com/topic/187739-limit-the-of-records-returned-from-a-scraping-session/#findComment-991203 Share on other sites More sharing options...
Modernvox Posted January 8, 2010 Author Share Posted January 8, 2010 yes. <?php $i = 1; //set start point; $limit = 5; //set limit; foreach ($posts as $post) { //print $post[0]; //HTML $post[2] = str_ireplace($url,"",$post[2]); //remove domain echo "<a href=\"$url{$post[1]}\">{$post[2]}<font size=\"3\">{$post[3]}<br />"; print "<BR />\n"; if ($i == $limit) { break; } $i++; } ?> something like that. Thanks Marcus. Much appreciated. Link to comment https://forums.phpfreaks.com/topic/187739-limit-the-of-records-returned-from-a-scraping-session/#findComment-991205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.