我在URL中做了一些操作,如下所示。PHP中传递URL的问题
$paginationPages=array();
$productCount=intval($htmlProductPage->find('div.paging span.itemcount',0)->plaintext);
if($productCount/16>1){
$pagecount=ceil($productCount/16);
for($i=2;$i<=$pagecount;$i++){
$urlSplitArray=explode('.',$productUrl);
$urlSplitCount=count($urlSplitArray);
$urlSplitArray[$urlSplitCount-2].="[".$i."]";
$paginationPages[]= implode('.',$urlSplitArray)."<br>";
}
#print_r($paginationPages);
}
和我得到的的foreach的所有环节进行进一步
foreach($paginationPages as $nextUrl){
#$nextUrl="http://www.100percent.co.nz/kitchen-and-cooking/ovens/freestanding[2].htm";
$htmlProductPage=file_get_html($nextUrl);
foreach($htmlProductPage->find("div.Item") as $element){ //error occurs here
echo $element->outertext;
}
}
变量$nextUrl
具有价值
“http://www.100percent.co.nz/kitchen-and-cooking/ovens/freestanding[2].htm”
我不能找到当我p的元素div.Item
动态链接链接。但是当我直接在for循环中分配url时,我可以找到相同的元素。为什么发生这种情况?
错误发生在哪里 - 您的代码是否成功使用'file_get_html'获取页面? – 2014-10-10 08:40:40
@ialarmedalien请检查我更新的问题。我已经提到了错误发生的位置 – DharanBro 2014-10-10 08:43:23
链接在每个循环内部进行了评论 – DharanBro 2014-10-10 08:46:18