Question
I am trying to post a request to log in to a website using the Requests module in Python but its not really working.
How-To
If the information you want is on the page you are directed to immediately after login, below is the simple code:
- payload = {'inUserName': 'USERNAME/EMAIL', 'inUserPass': 'PASSWORD'}
- url = 'http://www.locationary.com/home/index2.jsp'
- requests.post(url, data=payload)
- import requests
- # Fill in your details here to be posted to the login form.
- payload = {
- 'inUserName': 'username',
- 'inUserPass': 'password'
- }
- # Use 'with' to ensure the session context is closed after use.
- with requests.Session() as s:
- p = s.post('LOGIN_URL', data=payload)
- # print the html returned or something more intelligent to see if it's a successful login page.
- print p.text
- # An authorised request.
- r = s.get('A protected web page url')
- print r.text
- # etc...
沒有留言:
張貼留言