Advertisement
Guest User

Untitled

a guest
Oct 25th, 2017
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import requests
  2. import re
  3.  
  4. with requests.Session() as s:
  5.  
  6.     username = 'xxx@xxx.com'
  7.     password = 'xxx'
  8.  
  9.     login_url = 'https://xxx.com`'
  10.  
  11.     r = s.get(login_url)
  12.     html = r.text
  13.  
  14.     # Parse out the username field's name
  15.     username_regex = re.compile('\<input value="" id="username" type="text" name="(.*)"\>')
  16.     match = username_regex.search(html)
  17.     username_id = match.group(1)
  18.     print("UID: " + username_id)
  19.  
  20.     # Parse out the password field's name
  21.     pw_regex = re.compile('\<input value="" id="password" type="password" name="(.*)"\>')
  22.     match = pw_regex.search(html)
  23.     pw_id = match.group(1)
  24.     print("PWID: " + pw_id)
  25.  
  26.     # Now start an actual session where we log in
  27.     payload = {
  28.         username_id: username,
  29.         pw_id: password
  30.     }
  31.  
  32.     p = s.post(login_url, data=payload)
  33.  
  34.     # An authorised request.
  35.     r = s.get('https://xxx.com/logged_in_page/')
  36.     print(r.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement