how to use python to login page which requires session id responded by server on first request? -


i writing script log in webpage. using request , request.session module purpose.on first request login parameters server responses session id.how set session id further login same page.

url = "some url of login page" payload = {'username': 'p05989', 'password': '123456'} requests.session() s:     s.post(url1, data=payload)     sessionid = s.cookies.get('sessionid')     print(sessionid)     r = requests.get(url,data=payload)     print(r.text) 

in above code, server responses sessionid on first request.how use sessionid on second request?

you using requests.session(); handles cookies you, provided keep using session requests:

url = "some url of login page" payload = {'username': 'p05989', 'password': '123456'} requests.session() s:     # fetch login page     s.get(url)      # post login form     r = s.post(url1, data=payload)     print(r.text) 

you first need use get session id set before posting login form.

the sessionid cookie handled transparently you.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -