file_get_contents 返回 403 forbidden [英] file_get_contents returns 403 forbidden

查看:28
本文介绍了file_get_contents 返回 403 forbidden的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作网站爬虫.我在我的本地机器上做的,它在那里工作得很好.当我在我的服务器上执行相同的操作时,它显示 403 禁止错误.我正在使用 PHP 简单 HTML DOM 解析器.我在服务器上得到的错误是这样的:

I am trying to make a sitescraper. I made it on my local machine and it works very fine there. When I execute the same on my server, it shows a 403 forbidden error. I am using the PHP Simple HTML DOM Parser. The error I get on the server is this:

警告:file_get_contents(http://example.com/viewProperty.html?id=7715888)[function.file-get-contents]:失败打开流:HTTP 请求失败!HTTP/1.1 403 禁止在/home/scraping/simple_html_dom.php 上第 40 行

Warning: file_get_contents(http://example.com/viewProperty.html?id=7715888) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/scraping/simple_html_dom.php on line 40

触发它的代码行是:

$url="http://www.example.com/viewProperty.html?id=".$id;

$html=file_get_html($url);

我已经检查了服务器上的 php.ini 并且 allow_url_fopen 是 On.可能的解决方案是使用 curl,但我需要知道我哪里出错了.

I have checked the php.ini on the server and allow_url_fopen is On. Possible solution can be using curl, but I need to know where I am going wrong.

推荐答案

这不是脚本的问题,而是您请求的资源的问题.Web 服务器正在返回禁止"状态代码.

This is not a problem with your script, but with the resource you are requesting. The web server is returning the "forbidden" status code.

可能是因为它阻止了 PHP 脚本以防止抓取,或者如果您发出了太多请求,则可能是您的 IP.

It could be that it blocks PHP scripts to prevent scraping, or your IP if you have made too many requests.

您可能应该与远程服务器的管理员交谈.

You should probably talk to the administrator of the remote server.

这篇关于file_get_contents 返回 403 forbidden的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆