Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am writing a script to log in to some webpage. I using request and request.session module for this purpose.On first request with login parameters server responses a session id.How to set that session id for further login to same page.

url = "some url of login page"
payload = {'username': 'p05989', 'password': '123456'}
with requests.session() as 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 to use that sessionid on second request?

like image 352
heisenberg Avatar asked Mar 10 '14 12:03

heisenberg


1 Answers

import requests
import webbrowser

url = "https://www.invezta.com/investorsignup.aspx"


payload = {'login-email':  'email',
    'login-pwd': 'password'}

with requests.session() as s:
    # fetch the login page
    s.get(url)

    url1='https://www.invezta.com/Pdf_creator.aspx?User_ID='

    # post to the login form
    r = s.post(url1, data=payload)
    print(r.text)
like image 114
Vijay Avatar answered Nov 25 '22 15:11

Vijay