繁体   English   中英

PHP简单DOM发现不起作用

[英]PHP Simple DOM find not working

这让我停留了一会儿,所以我认为我会发布它。 我的问题是我的find->无法正常工作,而$ product_name即将变为null

    require 'mysql_con.php';
    require 'simple_html_dom.php';

    $html = file_get_html('http://www.xxxx.com/index.php?main_page=index&cPath=23');

    /* foreach($html->find('img') as $element) {
           echo $element->src . '<br>'; 
        }    */

    $find = $html->find('#specialsListing .specialsListBoxContents .indent a');

    $i=0;

    foreach ($find as $test) {

        $link = html_entity_decode($test->href);

        $linkgrab = file_get_html($link);

        $product_name = $linkgrab->find('#productName')->innertext;

        echo $product_name;

        break;

    }

尽管我正在为其他人发布此消息,但我仍然不确定为什么会出现以下情况,并且希望有人向我指出。

我得出的问题是:

$product_name = $linkgrab->find('#productName')->innertext;

应该

$product_name = $linkgrab->find('#productName', 0)->innertext;

基本上,产品名称必须编号。 但是我仍然很困惑,因为在这里: $find = $html->find('#specialsListing .specialsListBoxContents .indent a'); find命令对我有用,不需要编号,也认为选择器也是一个ID这一事实将使它变得不必要,如果有人可以指出我所缺少的那将是很好的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM