【发布时间】:2018-08-23 01:14:46
【问题描述】:
我暂时使用simplexml_load_file从几个网站获取RSS。
有时我会从其中一些网站收到错误,并且在大约 5 天内我遇到了来自 2 个特定网站的错误。
这是来自simplexml_load_file 的错误:
PHP Warning: simplexml_load_file(http://example.com/feed): failed to open stream: Connection timed out
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://example.com/feed"
以下是来自file_get_contents 的错误:
PHP Warning: file_get_contents(http://example.com/page): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
这就是我使用simplexml_load_file的方式:
simplexml_load_file( $url );
这就是我使用file_get_contents的方式:
file_get_contents( $url );
那是因为我没有使用代理或无效参数吗?
更新: 这两个网站正在使用防火墙或服务来检查机器人:
Accessing http://example.com/feed securely…
This is an automatic process. Your browser will redirect to your requested content in 5 seconds.
【问题讨论】:
-
因此,该网站正在使用服务来检测机器人,而您的代码是机器人,因此该服务正在检测您的代码并拒绝其访问。听起来该网站不希望您以这种方式访问它,并且正在按预期工作。
-
@IMSoP,这样做是为了防止 DDos 和类似类型的攻击,我只是想阅读 RSS
-
当然,但您的问题仍然是“我怎样才能绕过这个(身份不明的)站点保护”。如果行为不端,请与网站所有者或保护供应商联系;如果您正在做网站所有者不希望您做的事情,请不要这样做。
标签: php proxy rss simplexml file-get-contents