简单的html dom无法在find(id)中处理正斜杠

时间:2012-05-04 14:52:39

标签: php simple-html-dom

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>";
            }
        }
    }


}

1 个答案:

答案 0 :(得分:1)

斜杠被解释为XPath表达式的一部分,因此它正在寻找名为-IPods的子元素。没有XPath&#34;引用&#34;类型函数。我不确定添加反斜杠是否有效,但您可能更容易使用ID为[@id='fk-list-MP3-Players-/-IPods']

的普通属性选择器