2012-06-12 118 views
0

使用簡單的HTML DOM庫時,我遇到了一些網站的問題。當我試圖加載以下網址http://www.t-mobile.com/shop/phones/cell-phone-detail.aspx?cell-phone=HTC-One-S-Gradient-Blue&tab=reviews#BVRRWidgetID簡單的HTML DOM問題

我的PHP代碼:

<?php 

include "simple_html_dom.php"; 

$html=new simple_html_dom(); 
$url="http://www.t-mobile.com/shop/phones/cell-phone-detail.aspx?cell-phone=HTC-One-S- Gradient-Blue&tab=reviews#BVRRWidgetID"; 
$html->load_file($url); 
echo $html; 

?> 

PHP腳本沒有給出錯誤,但它顯示了每次下列內容。

Unsupported Browser 
It appears that you are viewing this page with an unsupported Web browser. This Web site works best with one of these supported browsers: 

Microsoft Internet Explorer 5.5 or higher 
Netscape Navigator 7.0 or higher 
Mozilla Firefox 1.0 or higher 

If you continue to view our site with your current browser, certain pages may not display correctly and certain features may not work properly for you. 

什麼問題?簡單的HTML DOM是否有限制?有沒有其他辦法可以解決這個問題?

+0

你的第一個問題是刮網站。但是,讓我們忘記,我需要設置一個適當的useragent –

回答

1

有些網站不允許直接報廢其內容。

您可以使用curl獲取html內容,然後使用dom對象的load()。

我希望它適合你。

1

只安裝您在simple_html_dom要求USERAGENT:

# Creating useragent array 
$useragent = array("http" => "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6"); 

# Creating a line from array 
$useragent = stream_context_create($useragent); 

# Starting Simple_HTML_Dom with our useragent 
$html = file_get_html($urlCategory, $useragent) 

所以,我們的要求將是比你的新瀏覽器。

0

設置用戶代理

$context = stream(); 
stream($context, array('user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n')); 
file_get_html('http://www.t-mobile.com/shop/phones/cell-phone-detail.aspx?cell-phone=HTC-One-S- Gradient-Blue&tab=reviews#BVRRWidgetID', 0, $context);