现在网站都做得贼拉恶心,boss要做个抓取程序,别人的网站要求登录,登录入口就一个,用curl写了个,死活不行,抓包一看才发下丫的做了n次跳转,无耻呀~~这不是逼我嘛~~招了n就没找到现成的~~唉自个动手吧~~~存个档
<?php
set_time_limit(1000);
$timeout = 1000;
$cookie_jar = tempnam('./','cookie');//cookie
function curl_redirect_exec($ch, &$redirects, $curlopt_returntransfer = false, $curlopt_maxredirs = 10, $curlopt_header = false) {
}
$useragent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)";
$request="user=user&pwd=pwd";
$loginurl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginurl);
curl_setopt($ch, CURLOPT_REFERER, 'index.asp');
curl_setopt($ch,CURLOPT_USERAGENT,$useragent);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_NOBODY,
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
@unlink($cookie_jar);