Last active
June 7, 2017 13:15
-
-
Save SakuraSa/36ddbfc4ffb331eb2eae to your computer and use it in GitHub Desktop.
Github_login.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding=utf-8 | |
import requests | |
from BeautifulSoup import BeautifulSoup | |
username = 'MY GITHUB ACCOUNT' | |
password = 'MY GITHUB PASSWORD' | |
session = requests.Session() | |
#get authenticity_token | |
page_login = BeautifulSoup(session.get('https://github.com/login').text) | |
post_form = page_login.find('div', id='login') | |
payload = { | |
ip['name']: ip['value'] | |
for ip in post_form.findAll('input') | |
if ip.get('value', None) | |
} | |
payload['login'] = username | |
payload['password'] = password | |
#send post | |
rsp = session.post('https://github.com/session', data=payload) | |
if session.cookies['logged_in'] != 'yes': | |
print 'login failed.' | |
else: | |
print 'login success.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment