find()这里是simple_html_dom库的一个函数,它应该在给定id / class时返回dom节点元素。
当$ id为“fk-list-MP3-Players - / - IPods”时, $urlFetched->find("#".$id)
始终无法找到并返回内容。我猜测问题是正斜杠和simple_html_dom,因为其他id和url没有问题(剪断)。
我该怎么办?我的程序几乎完成,依赖于简单的html dom。
由于
代码:
$urlAndIds = array(
array("http://www.flipkart.com/audio" , array('fk-list-Home-Audio', htmlentities("fk-list-MP3-Players-/-IPods"), 'fk-list-Accessories'),array('ALL','AllBrands')) );
foreach($urlAndIds as $uAI) {
$url = file_get_contents($uAI[0]) ;
$urlFetched = str_get_html($url) ;
if ($url == false){
echo 'page '.$uAI[0] . " not found" ."<br>" ."<br>";
} else {
foreach ($uAI[1] as $id) {
$idFound = $urlFetched->find("#".$id) ;
if(!$idFound) {
echo 'In page '.$uAI[0].' -id not found- '.$id ."<br>";
}
}
}
}
答案 0 :(得分:1)
斜杠被解释为XPath表达式的一部分,因此它正在寻找名为-IPods
的子元素。没有XPath&#34;引用&#34;类型函数。我不确定添加反斜杠是否有效,但您可能更容易使用ID为[@id='fk-list-MP3-Players-/-IPods']