当前位置:Gxlcms > PHP教程 > 关于cur采撷对方设置了来源页

关于cur采撷对方设置了来源页

时间:2021-07-01 10:21:17 帮助过:22人阅读

关于cur采集 对方设置了来源页
本帖最后由 u013366173 于 2015-03-03 22:35:09 编辑


Request URL:http://miaoo.sinaapp.com/cai.php
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:saeut=27.156.92.178.1425388310638157
Host:miaoo.sinaapp.com
If-Modified-Since:Tue, 03 Mar 2015 04:57:57 GMT
Referer:http://52jifenbao.com/cai/
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Response Headersview source
Connection:keep-alive
Content-Disposition:inline; filename=download.png
Content-Encoding:gzip
Content-Type:image/png
Date:Tue, 03 Mar 2015 14:31:09 GMT
Last-Modified:Tue, 03 Mar 2015 04:57:57 GMT
Server:nginx/1.4.4
Transfer-Encoding:chunked
Vary:Accept-Encoding
Via:10.67.15.22
X-Powered-By:PHP/5.3.29

要采集的是这个网址"http://miaoo.sinaapp.com/cai.php",成功的话显示是一张图片,有点类似验证码图片那种,对方应该设置了判断来源页,不用cookie和post数据,来源页为Referer:http://52jifenbao.com/cai/,请问怎么样才能成功采集呢,上面代码是360浏览器复制下来的头信息文件
------解决思路----------------------
常用的功能要写成函数或类保存起来,以备不时之需
而不是临阵擦枪
include 'curl/curl_get.php';
$url = 'http://miaoo.sinaapp.com/cai.php';
echo curl_get($url);

curl/curl_get.php
function curl_get($durl, $data=array()) {
$cookiejar = realpath('cookie.txt');
$t = parse_url($durl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$durl);
curl_setopt($ch, CURLOPT_TIMEOUT,5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_ENCODING, 1); //gzip 解码
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if($data) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$r = curl_exec($ch);
curl_close($ch);
return $r;
}

人气教程排行