使用PHP进行解析时,遵循Amazon Product页面链接

时间:2013-06-27 22:40:49

标签: php parsing dom amazon simple-html-dom

我写了一个PHP脚本来抓取亚马逊产品的产品评论页面链接。但是,我无法浏览产品页面。 [亚马逊每页仅显示12个产品]。

我的脚本使用Simple HTML Dom Parser。

这是我的脚本的一部分,它跟随到下一页产品的链接:

 if($nextPage=$html->find('#pagnNextLink',-1)) {
    $next = "http://amazon.com".$nextPage->href;

  // This works: 
// $next = "http://www.amazon.com/s/ref=sr_pg_2/179-2481337-1920701?rh=n%3A2625373011%2Cn%3A%212625374011%2Cn%3A2649512011%2Cp_n_date%3A2693527011%2Cp_n_theme_browse-bin%3A2650365011%2Cp_n_format_browse-bin%3A2650305011&page=2&ie=UTF8&qid=1372370539";

    echo "<p>".$next;


   getProducts($next);
}

问题:     最初加载到函数的基页继续加载,并且不访问当前页面中找到的下一页链接。

然而,注释行在上面的代码片段中有效。 :\ 有任何想法吗?

1 个答案:

答案 0 :(得分:0)

您的id错误

<a title="Next Page" id="pagnNextLink" class="pagnNext" href="/s/ref=sr_pg_2?rh=i%3Aaps%2Ck%3Atoothbrush&amp;page=2&amp;keywords=toothbrush&amp;ie=UTF8&amp;qid=1372374734">
            <span id="pagnNextString">Next Page</span>
            <span class="srSprite pagnNextArrow"></span>
         </a>

正确的ID应为#pageNextLink

相关问题