2013-02-02 26 views
0

我試圖獲取TNT包裹的最新狀態(在本例中爲「良好態度的貨件」),但無法使用簡單的html dom解析外部html 。獲得致命錯誤:調用一個成員函數查找()一個非對象在第6行使用簡單的html dom解析外部html獲取致命錯誤

<?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>'; 
?> 

我是什麼做錯了?

+0

http://stackoverflow.com/questions/7124823/file-get-html-displays-fatal-error –

+0

你的服務器上是否封鎖了file_get_contents?任何方式請爲我們發佈var_dump($ html) –

+0

@SholehFalahati獲取「bool(false)」 阻止的「file_get_contents」與「file_get_html」有什麼關係?我必須修改某些內容才能使其正常工作嗎? – vincchan

回答

0
file_get_html 

使用

file_get_contents 

從URL中讀取html頁面。您需要確保此功能未被阻止。在你的情況下,它似乎是

allow_url_fopen = Off 

在php.ini中它阻止它。

但無論如何,這是更好地使用

if ($html) 

成爲確保一切都做任何事情之前好。

+0

謝謝,是的,我確實改變了allow_url_fopen關閉,它現在正常工作。 – vincchan