cookie login and its storage

Request carries cookies in requests Request
1
Assign the cookies attribute of a Session instance to a CookieJar instance 2import http.cookiejar3 s= requests.session()#Instantiation4s.cookies = http.cookiejar.LWPCookieJar('mycookie. txt')#Instantiatethe cookie, set the save path5s.get('http://douban.com')#Sendrequest6s.save(ignore_expires=True, ignore_discard=True) #Savedto mycookie.txt7s.cookies.clear() #Clear cookiesin the browser8s.cookies.load(' mycookie.txt ' ) #Load 9 from a file # s.cookies.revert() # This method is equal to clearing and then loading the next login


  
1 session= request.session()
 2 session.cookies = cookielib.LWPCookieJar(filename= ' Saved cookie file name ' )
 3 session.cookies.load(ignore_discard=True, ignore_expires=True) #Load cookies in the file 
4 response = self.session.get(url= ' http://www.zhihu.com ' , verify=True, headers=headers) #Access web page 5 with cookies 
print (response.url)             
 
 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324855288&siteId=291194637