2016-08-25 18 views
0

我有一個file_get_html()的問題,我不明白爲什麼它不起作用,你能幫我嗎?我的代碼file_get_html()不與空氣淨化器

$html = file_get_html('https://www.airbnb.fr/'); 

if ($html) { 
    echo "good"; 
} 

祝您有美好的一天!

+0

你能定義什麼你是什麼意思,當你說它不起作用?它是否返回錯誤消息,還是不返回數據? – MichaelDotKnox

回答

0

我認爲,服務器只是阻止你的請求,你將無法使用簡單的HTTP請求從它獲取數據。

您可以嘗試使用捲曲,代理,或兩者(有準備使用的解決方案爲此,如:AngryCurl,或RollingCurl)

0

它不工作,因爲你必須包括simple_dom_html類,使其工作。你可以找到他們的官方網頁上的代碼:

http://simplehtmldom.sourceforge.net/

然後,你可以簡單地得到這樣的HTML輸出它:

// Dump contents (without tags) from HTML 
echo file_get_html('http://www.google.com/')->outertext; 

,或者如果您希望將結果保存在變量

// Dump contents (without tags) from HTML 
$html = file_get_html('http://www.google.com/')->outertext; 

更多信息:http://simplehtmldom.sourceforge.net/