0

在使用简单 HTML DOM 库时,我遇到了一些网站的问题。当我尝试加载以下网址http://www.t-mobile.com/shop/phones/cell-phone-detail.aspx?cell-phone=HTC-One-S-Gradient-Blue&tab=reviews#BVRRWidgetID

我的 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.

问题是什么?Simple HTML DOM 有限制吗?有没有其他方法可以解决这个问题?

4

3 回答 3

1

有些网站不允许直接废弃其内容。

您可以使用curl获取 html 内容,然后使用 dom 对象的 load()。

我希望它对你有用。

于 2012-11-06T11:50:20.340 回答
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)

因此,我们的请求将来自比您更新的浏览器。

于 2015-10-31T21:23:13.227 回答
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);
于 2016-10-21T06:52:30.667 回答