php file抓取不到内容,这个网站,为啥我用file_get_contents抓取不到任何内容?

http://www.hdwallpapersimages.com/

浏览器显示正常,先使用file_get_contents,抓取内容为空,用ChinaZ的百度蜘蛛和谷歌蜘蛛模拟抓取,还是请求超时,于是我干脆复制我浏览器的header,用file_get_contents抓取,还是抓取为空,这是我的代码:

$opts = array(

'http'=>array(

'method'=>"GET",

'header'=>"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n".

"Accept-Encoding:gzip, deflate, sdch\r\n".

"Accept-Language:zh-CN,zh;q=0.8,en;q=0.6\r\n".

"Cache-Control:max-age=0\r\n".

"Cookie:viewed_cookie_policy=yes; __utmt=1; __utma=37938810.875942873.1452954236.1453114091.1453209277.3; __utmb=37938810.30.10.1453209277; __utmc=37938810; __utmz=37938810.1452954236.1.1.utmcsr=bing|utmccn=(organic)|utmcmd=organic|utmctr=hd%20wallpaper; __unam=eb5fde1-1524ad24043-4a580705-62\r\n".

"Host:www.hdwallpapersimages.com\r\n".

"Proxy-Connection:keep-alive\r\n".

"Upgrade-Insecure-Requests:1\r\n".

"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36\r\n"

)

);

$context = stream_context_create($opts);

echo file_get_contents('http://www.hdwallpapersimages.com', false, $context);

回复内容:

http://www.hdwallpapersimages.com/

浏览器显示正常,先使用file_get_contents,抓取内容为空,用ChinaZ的百度蜘蛛和谷歌蜘蛛模拟抓取,还是请求超时,于是我干脆复制我浏览器的header,用file_get_contents抓取,还是抓取为空,这是我的代码:

$opts = array(

'http'=>array(

'method'=>"GET",

'header'=>"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n".

"Accept-Encoding:gzip, deflate, sdch\r\n".

"Accept-Language:zh-CN,zh;q=0.8,en;q=0.6\r\n".

"Cache-Control:max-age=0\r\n".

"Cookie:viewed_cookie_policy=yes; __utmt=1; __utma=37938810.875942873.1452954236.1453114091.1453209277.3; __utmb=37938810.30.10.1453209277; __utmc=37938810; __utmz=37938810.1452954236.1.1.utmcsr=bing|utmccn=(organic)|utmcmd=organic|utmctr=hd%20wallpaper; __unam=eb5fde1-1524ad24043-4a580705-62\r\n".

"Host:www.hdwallpapersimages.com\r\n".

"Proxy-Connection:keep-alive\r\n".

"Upgrade-Insecure-Requests:1\r\n".

"User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36\r\n"

)

);

$context = stream_context_create($opts);

echo file_get_contents('http://www.hdwallpapersimages.com', false, $context);

你抓取的网站打不开么

因为网站我也打不开,哈哈哈哈,在你运行的机子上 直接curl 看看有内容么

相关标签:php

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值