獲取的 Cookie 為什麼無法用於爬蟲

Python_xiaohe發表於2019-11-05

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)
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章