【发布时间】:2013-03-20 07:55:30
【问题描述】:
我尝试使用 file_get_contents() 解析网站的 html。
我从我的网站运行代码。
一开始还可以,但是突然出现这个错误:
Warning: file_get_contents(http://www.***.com/) [function.file-get-contents]: failed to open stream: HTTP request failed!
我尝试了其他网站,它运行良好。我从我的其他网站运行代码,它运行良好。
所以我在这里搜索并使用了cURL代码:
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.***.com/');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
但它只是返回一个空白页。
看起来我试图获取内容的网站被阻止或将我的网站域列入黑名单。
我有办法摆脱这个吗??
【问题讨论】:
-
网站的链接是什么?
-
@Antony azlyrics.com
-
在这里工作正常:codepad.viper-7.com/4Kt71m
标签: php curl file-get-contents