PHP - file_get_contents 系统错误?

发布于 2024-10-09 08:44:13 字数 447 浏览 0 评论 0原文

我正在尝试从 url 解析 html。我这样做:

$html = file_get_contents($someURL);
echo $html;

但是当我运行该脚本时,页面显示:

UISCGI (software8a-web; software8a-link):
This site is best viewed with Netscape 4.6 or 4.7 or Internet Explorer 5 and greater.
At this time Netscape 6 is not supported for Link usage.

我还尝试了 CURLing url,同时将 IE7 伪装为用户代理。

这里出了什么问题?我在谷歌上找不到这个错误。我该如何克服这个系统错误?

I'm trying to parse the html from a url. I do this:

$html = file_get_contents($someURL);
echo $html;

But when I run that script, the page shows this:

UISCGI (software8a-web; software8a-link):
This site is best viewed with Netscape 4.6 or 4.7 or Internet Explorer 5 and greater.
At this time Netscape 6 is not supported for Link usage.

I also tried CURLing the url, while faking IE7 as the User Agent.

What's going wrong here? I couldn't find this error anywhere with Google. How do I get past this system error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方觉久 2024-10-16 08:44:13

我找到了这样一个地址,伪造用户代理效果很好。也许您的情况下标头的设置是错误的。

简单的例子:(

<?php
   //fake IE6
  ini_set('user_agent', "Mozilla/4.0 (compatible; MSIE 6.0)\r\n");
   //request
  echo file_get_contents('http://www.bu.edu/link/');
?>

没有 ini_set() 我得到和你一样的输出)

注意:从 PHP5 开始,file_get_contents() 还允许通过可选的上下文参数设置标头-

I found such an adress, faking of the user-agent works fine. Maybe the setting of the header is wrong in your case.

simple example:

<?php
   //fake IE6
  ini_set('user_agent', "Mozilla/4.0 (compatible; MSIE 6.0)\r\n");
   //request
  echo file_get_contents('http://www.bu.edu/link/');
?>

(without the ini_set() I get the same output like you)

Note: From PHP5 on file_get_contents() also allows setting of headers via the optional context-parameter-

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文