Skip to content

Instantly share code, notes, and snippets.

@itsjzt
Created August 16, 2018 15:55
Show Gist options
  • Save itsjzt/dff9091f9c3014318f22b05108cd20e9 to your computer and use it in GitHub Desktop.
Save itsjzt/dff9091f9c3014318f22b05108cd20e9 to your computer and use it in GitHub Desktop.
import requests, lxml.html
s = requests.session()
### Here, we're getting the login page and then grabbing hidden form
### fields. We're probably also getting several session cookies too.
login = s.get('https://github.com/login')
login_html = lxml.html.fromstring(login.text)
hidden_inputs = login_html.xpath(r'//form//input[@name="authenticity_token"]')
form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
### Now that we have the hidden form fields, let's add in our
### username and password.
form['utf8'] = '✓'
form['login'] = 'LOl@ I forgot to backspace my username'
form['password'] = 'LOl@ I forgot to backspace my passsword'
response = s.post('https://github.com/session', data=form)
n = s.get('https://github.com/settings/profile')
with open('C:\\Users\\jztsaurabh\\Desktop\\rough\\data.html', 'w', encoding="utf-8") as file:
file.write(response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment