First, get a random string token
1 token to access the login page for a random string
request the URL of:
https://github.com/login
request method:
GET
request header:
COOKIES
the User-Agent: Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit / 537.36 (KHTML , like Gecko) Chrome / 75.0.3770.100 Safari / 537.36
II. parse and extract the token string
# regular
<input type = "hidden" name = "authenticity_token" value = "(. *?) "/>
source
import requests import re login_url = 'https://github.com/login'
# Login request header information page
login_header = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)' } login_res = requests.get(url=login_url, headers=login_header) # print(login_res.text)
# Parse extracted token string
authenticity_token = re.findall( '<input type="hidden" name="authenticity_token" value="(.*?)" />', login_res.text, re.S )[0] print(authenticity_token)
# Cookies to obtain information login page
# print(type(login_res.cookies)) # print(type(login_res.cookies.get_dict())) login_cookies = login_res.cookies.get_dict()
# 2 Start registering GitHub
'' '
POST request to automatically log github:
request the URL of:
https://github.com/session
request method:
POST
request header:
Cookie
the User-Agent: Mozilla / 5.0 (Macintosh; Intel Mac OS the X-10_14_3 ) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 75.0.3770.100 Safari / 537.36
request body:
the commit: Sign in
UTF8: ✓
authenticity_token:
UBXaPbyTraHYf9KzcMjmc4djtmqHOeiyUkKssP6drR0X67mcZJJnfqnMT / QnizSRoMdkK8D1YupHoADr31OHew ==
njrbYmGyInLNiNPpvpgxHUDfZ79O1AHDrrDxjSs8HchVBOaAZN2e2v8 pOGaIxdC ++ + + DyxbMGiUE xSMNAkEZVg ==
Login: the king cover tiger
password: uphill fight rats
webauthn-support: supported
'' '
# The session login url
session_url = 'https://github.com/session'
# Request header
session_headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)' }
#-Information request
form_data = { "commit": "Sign in", "utf8": "✓", "authenticity_token": authenticity_token, "login": "cl0007", "password": "cl875091554", "webauthn-support": "supported" } session_res = requests.post(url=session_url, headers=session_headers, cookies=login_cookies, data=form_data) with open('github3.html', 'w', encoding='utf-8') as f: f.write(session_res.text)