function request_url_data($data) #获取保存COOKIE { $cookieSuccess = __DIR__."/cookie.txt";#cookie保存文件地址 $data['user'] = '用户名'; $data['pwd'] = '密码'; $requesturl = 'http://GET登陆提交地址?'.http_build_query($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $requesturl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieSuccess); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $data=curl_exec($ch); curl_close($ch); return $data; } function get_list($requesturl)#携带COOKIE请求获取登陆后的内容 { $cookieSuccess = __DIR__."/cookie.txt"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $requesturl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieSuccess); //使用上面获取的cookies curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); $data=curl_exec($ch); curl_close($ch); return $data; }
相关博文
PHP curl 携带cookie请求抓取源码,模拟登陆。