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条评论1111111111 Lv.1
Chrome 94.0.4606.71
Windows 回复
1234444444444qqqqq钱钱钱
江苏省 移动
Alexan456 Lv.1 回复
6666666 fA啊谢谢
上海市 移动
张小三 Lv.1
Chrome 69.0.3947.100
Windows 回复
山东省济南市 移动
潇洒A啊谢谢 Lv.1
Chrome 86.0.4240.198
Windows 回复
44444444444444444444444444444444444444潇洒A啊谢谢
江苏省南京市 联通
撒大大 Lv.1 回复
广西南宁市 电信
刚刚去要饭了85 Lv.1 回复
哈哈哈
安徽省合肥市 电信
yll682 Lv.1
Chrome 87.0.4280.101
Android 11 回复
来了
福建省福州市 广电网
电脑骇客小白科技 Lv.1 回复
流量来了
山东省潍坊市 移动
Hsiao yu ` Lv.1 回复
来了
四川省 移动
温水煮青蛙 Lv.1 回复
你好
山东省枣庄市 电信