I want to start the script to login into one website and store the cookies in some file, and later i wanna start the script to visit other pages of that website but with same cookies, so I do not have to login everytime for everypage that I wanna visit:
import requests
import random
import sys
link = sys.argv[1]
link = link.replace("%26", "&")
link = link.replace("######", "&")
if len(sys.argv) > 3 :
username = sys.argv[2]
password = sys.argv[3]
else:
username = ''
password = ''
###LOGIN PART###
payload = {
'username': username,
'_spring_security_remember_me': '',
'password': password,
'targetUrlNonEncoded': 'false',
}
UAS = (
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36",
)
ua = UAS[random.randrange(len(UAS))]
headers = {'user-agent': ua}
s = requests.Session()
r = s.post(link, headers=headers,data = payload)
print(r.text.encode('utf8'))
I did this and it works great, can someone help me how from this i can save the cookies and use them again later?