最基本的操作如下
$curlPost = 'a=1&b=2';//模拟POST数据
$cookie_file = tempnam('./temp','kie');//可选,保存session到cookie中实现模拟登录 $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0')); //构造IP curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/"); //构造来路 curl_setopt($ch,CURLOPT_URL, 'http://www.baidu.com');//需要抓取的页面路径 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //抓取重定向后的页面 curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);//post值
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);//存储登录session
$file_contents = curl_exec($ch);//抓取的内容放在变量中 curl_close($ch)