1、伪造客户端IP地址,伪造访问referer:(一般情况下这就可以访问到数据了)curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-FORWARDED-FOR:110.85.108.185', 'CLIENT-IP:110.85.108.185']);
curl_setopt($curl, CURLOPT_REFERER, 'http://4dn.net/test.php');2、如是上面的还是不行,可能是别人抓到了真实IP,这时候我们就使用代{过}{滤}理访问# 详细方式
curl_setopt($curl, CURLOPT_PROXY, 'x.x.x.x'); //代{过}{滤}理服务器地址
curl_setopt($curl, CURLOPT_PROXYPORT, 80); //代{过}{滤}理服务器端口
//curl_setopt($curl, CURLOPT_PROXYUSERPWD, ':''); //http代{过}{滤}理认证帐号,username:password的格式
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代{过}{滤}理模式
# 简写方式
curl_setopt($curl, CURLOPT_PROXY, 'http://x.x.x.x:80');3、还有一种就是用浏览器可以访问,用curl不行。(对方检查了useragent,如果没有就认为是非法来源等验证了)$useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ';
$useragent.= '(KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36';
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);PHP完整Curl抓取数据函数:/**
* 请求接口
* [url=home.php?mod=space&uid=718080]@access[/url] public
* [url=home.php?mod=space&uid=952169]@Param[/url] string $url 请求地址
* @param array $data 提交参数 没有get 有post
* [url=home.php?mod=space&uid=155549]@Return[/url] bean|array
*/
public function send($url='')
{
set_time_limit(0);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-FORWARDED-FOR:127.0.1.1', 'CLIENT-IP:127.0.1.1']);
curl_setopt($curl, CURLOPT_REFERER, 'http://4dn.net/demo.php');
curl_setopt($curl, CURLOPT_PROXY, 'http://127.0.0.1:80');
$useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ';
$useragent.= '(KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36';
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
if(!empty($data) && is_array($data)){
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
$html = curl_exec($curl);
if($error=curl_errno($curl)){
return false;
}
curl_close($curl);
return $html;
}
评论
172条评论a'ゞ不言 Lv.1
Internet Explorer
iPhone iOS 16.1 回复
六
重庆市 电信
腾讯视频 Lv.3
Chrome 86.0.4240.198
Windows 回复
不错不错,味道好极了
广东省深圳市 鹏博士长城宽带
新云 Lv.1
Internet Explorer
iPhone iOS 16.3.1 回复
不错不错,味道好极了
上海市 电信
接口连接阿道夫 Lv.1
Chrome 111.0.0.0
Windows 回复
北京市 电信
787447 Lv.1
Chrome 86.0.4240.198
Windows 回复
支持一下,黑蜘蛛博客有你更精彩
云南省红河州 联通
q9837762 Lv.1
Sogou Explorer
Windows 7 x64 Edition 回复
够厉害的啊
江苏省南京市 电信
q9837762 Lv.1
Internet Explorer
iPhone iOS 14.8.1 回复
厉不厉害兄弟们
江苏省南京市 电信
上善若水linwei Lv.1
Chrome 109.0.0.0
Windows 回复
感谢楼主分享
广东省广州市越秀区 电信
腾讯视频 Lv.3
Chrome 112.0.0.0
Windows 回复
拿来学习
广东省广州市 联通
jdj Lv.1
Android Webkit
Android 10 回复
可以吗
上海市 电信