首页 >后端开发 >php教程 >关于cur采撷 对方设置了来源页

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

WBOY
WBOY原创
2016-06-13 12:16:261088浏览

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

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

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

curl/curl_get.php
<?php<br />function curl_get($durl, $data=array()) {<br />  $cookiejar = realpath('cookie.txt');<br />  $t = parse_url($durl);<br />  $ch = curl_init();<br />  curl_setopt($ch, CURLOPT_URL,$durl);<br />  curl_setopt($ch, CURLOPT_TIMEOUT,5);<br />curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);<br />  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);<br />  curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");<br />  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);<br />  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);<br />  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);<br />  curl_setopt($ch, CURLOPT_ENCODING, 1); //gzip 解码<br />  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);<br />if($data) {<br />  curl_setopt($ch, CURLOPT_POST, 1);<br />  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);<br />}<br />  $r = curl_exec($ch);<br />  curl_close($ch);<br />  return $r;<br />}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn