defcookiejar_from_str(cookies_str): ''' 将cookies字符串转换为cookiejar ''' cookies=dict([item.split('=',1) for item in cookies_str.split(';')]) print(cookies) cookies=requests.utils.cookiejar_from_dict(cookies) return cookies
if __name__ == '__main__': # cookies字符串 cookies_str='''openid2ticket_okSCe0vbk_v5067L-AuViT1wrkEg=ARU37unMfUwam3yNHXFcw5CMFvTHMvmBnjjS8A8= '''.strip() # 这里我手动截去了大部分cookies字符串,明白意思即可 # headers headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3722.400 QQBrowser/10.5.3738.400' }