下面是我的代码,我网上找的高匿代理ip做实验,抓取http://www.ip138.com/ 但是上面显示的还是我真实ip说明代理ip没有起作用,有谁能分析下到底为什么。 function get_html($url,$data=array(),$html_char='UTF-8',$is_ssh='http'){ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_PROXY,'111.12.117.67');
curl_setopt($ch, CURLOPT_PROXYPORT,'83');
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('CLIENT-IP:113.207.63.26', 'X-FORWARDED-FOR:113.207.63.26'));
curl_setopt ($ch, CURLOPT_TIMEOUT, 6000);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'); if($is_ssh=='SSL'){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
if(!empty($data)){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$output = curl_exec($ch);
if($html_char!='UTF-8'){
$output=mb_convert_encoding($output, "UTF-8", $html_char);
}
$info = curl_getinfo($ch);
curl_close($ch);
$returntemp = array('output'=>$output,'info'=>$info);
return $returntemp['output'];
}
$url='http://www.ip138.com/';
$date=get_html($url);echo $date;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_PROXY,'111.12.117.67');
curl_setopt($ch, CURLOPT_PROXYPORT,'83');
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('CLIENT-IP:113.207.63.26', 'X-FORWARDED-FOR:113.207.63.26'));
curl_setopt ($ch, CURLOPT_TIMEOUT, 6000);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'); if($is_ssh=='SSL'){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
if(!empty($data)){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$output = curl_exec($ch);
if($html_char!='UTF-8'){
$output=mb_convert_encoding($output, "UTF-8", $html_char);
}
$info = curl_getinfo($ch);
curl_close($ch);
$returntemp = array('output'=>$output,'info'=>$info);
return $returntemp['output'];
}
$url='http://www.ip138.com/';
$date=get_html($url);echo $date;
而是网页打开之后,又发了一个请求:
http://1111.ip138.com/ic.asp
这个请求才是在网页中显示ip的网址,所以用curl抓这个页面就好了