simple_html_dom找不到我的元素


simple_html_dom not finding my element

我正在尝试从亚马逊上的价格进行练习。

      <?php
      require('simple_html_dom.php');
      $get = $_GET['id'];
      $get_url = 'http://www.amazon.co.uk/s/field-keywords='.$get;
       echo $get_url;
      // Retrieve the DOM from a given URL
      $html = file_get_html($get_url);
      foreach($html->find('li[class=newp]') as $e) 
        echo $e->plaintext . '<br>';

我尝试了几种不同的方法:

李[类=新P]

。价格

ul[class=rsltL]

但它没有返回任何东西,我做错了什么?

我也尝试返回标题:

.

lrg.粗体

尝试过Xpath,什么都没有。

谢谢

你的代码很好。您的PHP设置很可能是罪魁祸首。

error_reporting(E_ALL);
ini_set('display_errors', '1');

在 PHP 脚本的开头,看看它是否打印出任何有用的错误。

另外,请注意,simple_html_dom内部使用 file_get_contents() 函数来抓取页面内容。 因此,您可能需要运行file_get_contents($get_url)以查看会发生什么。

如果该功能不起作用,那么它绝对是您的PHP设置。 在这种情况下,我建议在标题中启动另一个带有该问题的线程。

不过,这可能会有所帮助:PHP file_get_contents在本地主机上不起作用