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

后端 未结 2 689
执笔经年
执笔经年 2021-02-08 13:30

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

相关标签:
2条回答
  • 2021-02-08 14:11

    You are already using requests.session(); it handles cookies for you, provided you keep using the session for all your requests:

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

    You probably do first need to use GET to get the session id set before posting to the login form.

    The SESSIONID cookie is handled transparently for you.

    0 讨论(0)
  • 2021-02-08 14:34
    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)
    
    0 讨论(0)
提交回复
热议问题