获取的 Cookie 为什么无法用于爬虫


import requests
import re

def Get_Cookie(url):
    session = requests.Session()
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36'
    }

    req = session.get(url, headers=headers)
    p = str(session.cookies)

    Cookie = re.findall(r"Cookie (.+?) for",p)
    #获取当前的Cookie
    Cookie = Cookie[0] + ";" +Cookie[1]
    print(Cookie)
    return Cookie

if __name__=='__main__':
    url = 'https://weibo.com/u/5644764907?page=1&is_all=1'
    Get_Cookie(url)
讨论数量: 1

可能原因是失效.

1天前 评论

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!