链接:http://blog.csdn.net/hechurui/article/details/45870041
为了批量抓一些素材,写了段程序,自动抓100多个页面的5000多张图,对方站点防盗链开启了,只能用图片所在页面地址做reffer才能 抓图,于是用curl伪造reffer。函数贴出来,备忘,函数本身可以模仿Baidu蜘蛛。
function baiduSpider($url$reffer){
$ch = curl_init();
$user_agent = “Baiduspider+(+http://www.baidu.com/search/spider.htm)”;//这里模拟的是百度蜘蛛
curl_setopt($ch CURLOPT_URL $url);
curl_setopt($ch CURLOPT_HEADER false);
curl_setopt($ch CURLOPT_RETURNTRANSFER 1);
curl_setopt($ch CURLOPT_REFERER $reffer);//这里写一个来源地址,可以写要抓的页面的首页
curl_setopt($ch CURLOPT_USERAGENT $user_agent);
$temp=curl_exec($ch);
return $temp;
}