Php自动转到下一页并抓取


Php auto go to the next page and scrape

我是Php新手,我正在尝试编写一个工具来抓取亚马逊产品标题现在,我可以刮第一页,但我需要的工具去下一页,直到没有剩下的页面,做同样的任务,就像第一页,这是刮。下面是代码:

    <?php
$file_string = file_get_contents('http://www.amazon.com/s/ref=lp_3737671_pg_1?rh=n%3A1055398%2Cn%3A%211063498%2Cn%3A3206324011%2Cn%3A3737671&page=1&ie=UTF8&qid=1361609819');
preg_match_all('/<span class="lrg bold">(.*)<'/span>/i', $file_string, $links);
for($i = 0; $i < count($links[1]); $i++) {
echo $links[1][$i] . '<br>';
}
?>

任何帮助都是感激的…

要将所有页面HTML作为一个变量,这将达到目的

    <?php
    $html = '';
    $file_string = file_get_contents('http://www.amazon.com/s/ref=lp_3737671_pg_1?rh=n%3A1055398%2Cn%3A%211063498%2Cn%3A3206324011%2Cn%3A3737671&page=1&ie=UTF8&qid=1361609819');
    preg_match_all('/<span class="lrg bold">(.*)<'/span>/i', $file_string, $links);
    for($i = 0; $i < count($links[1]); $i++) {
        $html .= file_get_contents($links[1][$i]);
    }
    echo "all pages combined:'n".$html;
    ?>

然而,更有可能的是,您的服务器将超时,耗尽内存或其他东西将出错。要抓取HTML内容,最好先创建一个URL列表,然后一次抓取一个。您可以通过一个HTML页面通过AJAX调用scraper来实现这一点。