Loading... # [PHP curl 携带cookie请求抓取源码,模拟登陆](https://blog.p2hp.com/archives/11091) ```php 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; } ``` 最后修改:2023 年 08 月 12 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏