mercredi 1 décembre 2021

Login with python form requests

Good morning I need your help, I would like to perform some web scraping to this website, but where to login first, I made a code, but I can not understand if it works and the login is done correctly.. also if once I am connected to my account via python the session remains open`? Thank you!

 `import requests

payload = {
         'j_username': 'username',
         'j_password': 'password'
    }

# Use 'with' to ensure the session context is closed after use.
with requests.Session() as s:
    p = s.post('https://sgv.ivu-cloud.com/mbweb/j_security_check', data=payload)
    # print the html returned or something more intelligent to see if it's a successful login page.
    print (p)

    # An authorised request.
    r = s.get('https://sgv.ivu-cloud.com/mbweb/main/matter/desktop/main-menu#duties')
    print (r.text)
        # etc...



Aucun commentaire:

Enregistrer un commentaire