php使用curl抓取一个网站的内容被拒绝 200
展开全部
带上header 和 cookie
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要看具体原因,说不定你的ip被封了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-07-28 · 知道合伙人互联网行家
关注
展开全部
<?php
$binfo =array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)','Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)','Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)',$_SERVER['HTTP_USER_AGENT']);//218.242.124.16*
//125.90.88.*
$cip = '218.242.124.'.mt_rand(0,254);
$xip = '218.242.124.'.mt_rand(0,254);
$header = array(
'CLIENT-IP:'.$cip,
'X-FORWARDED-FOR:'.$xip,
);
function getimgs( $url,$data,$userinfo,$header){
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, "$url");
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);curl_setopt ($ch, CURLOPT_REFERER, "http://www.sgs.gov.cn/lz/etpsInfo.do?method=index");curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt ($ch, CURLOPT_USERAGENT, "$userinfo");curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
$url ='http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch';$u = $binfo[mt_rand(0,3)];
$data = array(
'keyWords'=>'上海科波',
'searchType'=>'1'
);
$html = (getimgs($url,$data,$u,$header));//替换链接地址
$html = str_replace('href="#"', 'href="http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch#"', $html);echo $html;
?>
$binfo =array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)','Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)','Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)',$_SERVER['HTTP_USER_AGENT']);//218.242.124.16*
//125.90.88.*
$cip = '218.242.124.'.mt_rand(0,254);
$xip = '218.242.124.'.mt_rand(0,254);
$header = array(
'CLIENT-IP:'.$cip,
'X-FORWARDED-FOR:'.$xip,
);
function getimgs( $url,$data,$userinfo,$header){
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, "$url");
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);curl_setopt ($ch, CURLOPT_REFERER, "http://www.sgs.gov.cn/lz/etpsInfo.do?method=index");curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt ($ch, CURLOPT_USERAGENT, "$userinfo");curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
$url ='http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch';$u = $binfo[mt_rand(0,3)];
$data = array(
'keyWords'=>'上海科波',
'searchType'=>'1'
);
$html = (getimgs($url,$data,$u,$header));//替换链接地址
$html = str_replace('href="#"', 'href="http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch#"', $html);echo $html;
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询