我正在尝试使用Simple HTML DOM从Zen-cart商店按产品部分搜索产品数据。我可以从第一页抓取数据,但是当我尝试加载“下一页”产品时,网站会返回index.php登录页面。
如果我直接使用* http://URLxxxxxxxxxx.com/index.php?main_page = index&amp; cPath = 36&amp; sort = 20a&amp; page = 2 *,它会从第2页中删除产品信息。< / p>
如果我使用cURL,也会发生同样的事情。
getPrices('http://URLxxxxxxxxxx.com/index.php?main_page=index&cPath=36');
function getPrices($sectionURL) {
$opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n" . "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n" . "Cookie: zenid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"));
$context = stream_context_create($opts);
$html = file_get_contents($sectionURL, false, $context);
$dom = new simple_html_dom();
$dom -> load($html);
//Do cool stuff here with information from page.. product name, image, price and more info URL
if ($nextPage = $dom -> find('a[title= Next Page ]', 0)) {
$nextPageURL = $nextPage -> href;
echo $nextPageURL;
$dom -> clear();
unset($dom);
getPrices($nextPageURL);
} else {
echo "\nNo more pages to scrape!!";
$dom -> clear();
unset($dom);
}
}
有关如何解决此问题的任何想法?