0

我正在尝试获取 TNT 包裹的最新状态(在本例中为“发货状况良好”),但无法使用简单的 html dom 解析外部 html。出现致命错误:在第 6 行调用非对象上的成员函数 find()

<?php 
include("simple_html_dom.php");

$html = file_get_html('http://www.tnt.com/webtracker/tracking.do?&cons=323626321');

$e=$html->find('table.appTable', 1)->find('tr[valign=top]', 0)->find('td', 3);

echo $e;
?> 

甚至来自http://simplehtmldom.sourceforge.net/index.htm的示例代码也给了我同样的错误

<?php
$html = file_get_html('http://www.google.com/');
foreach($html->find('img') as $element) 
   echo $element->src . '<br>';
?>

我究竟做错了什么?

4

1 回答 1

0
 file_get_html 

利用

 file_get_contents

从 url 读取 html 页面。您需要确保此功能未被阻止。在你的情况下,它似乎是

 allow_url_fopen = Off

在 php.ini 中阻止了它。

但无论如何,最好使用

 if ($html)

在做任何事情之前确保一切顺利。

于 2013-02-02T15:53:58.343 回答