2017-04-15 84 views
1

我在使用HTML DOM時遇到了某些網頁的問題。我設置了用戶代理並打開一個流,但響應似乎是空的。simple_html_dom響應爲空

我注意到這些網頁的一些內容是HTML中有未封閉的標籤。這可能會影響簡單的HTML DOM?

我的代碼是:

<?php 

include_once 'simple_html_dom.php'; 

$url_to_compare = 'http://www.idigic.net/buy-instagram-followers/'; 

ini_set('user_agent', $_SERVER['HTTP_USER_AGENT']); 

$html = file_get_html($url_to_compare)->plaintext; 

echo $html; 

?> 
+0

_「這可能會影響簡單的HTML DOM?」_它可以。你可以嘗試用['tidy :: repairString()'](http://us3.php.net/manual/en/tidy.repairstring.php)清理HTML。 –

+0

不工作! @AlexHowansky –

+0

嘗試使用捲曲。我也不認爲'ini_set'會做任何事情。 – pguardiario

回答

-2

檢查此鏈接

http://simplehtmldom.sourceforge.net/manual.htm

我認爲這是要緊妳。

file_get_html其獲取數組,因此它不會在echo中顯示任何內容。使用print_r可能是工作。

+1

請[僅限鏈接回答](http://meta.stackoverflow.com/tags/link-only-answers/info)。答案是「幾乎不超過鏈接到外部網站」[可能會被刪除] – Quentin

+0

Print_r確實會返回一些內容,但我無法訪問任何元素或明文渲染一切無用。 –