PHP curl 携带cookie请求抓取源码,模拟登陆

dafenqi
2023-08-12 / 0 评论 / 13 阅读 / 正在检测是否收录...

PHP curl 携带cookie请求抓取源码,模拟登陆

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;
}
0

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/testblog.58heshihu.com/var/Widget/Archive.php on line 1032

评论 (0)

取消