github登錄


思路

測試1

1.如果到github的登錄界面,清除一遍緩存之后請求,無法登錄 422
登錄界面是從login界面跳轉的,說明login中存了一些內容(cookies)
獲取authenticity_token與timestamp_secret

2.session為登錄接口,攜帶相應的數據即可

代碼

import requests
import re
username = 'xxxx'
password = 'xxxx'

url_login = 'https://github.com/login'
header = {
    'User-Agent' :'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
}

login_response = requests.get(url=url_login, headers=header)

#獲取authenticity_token與timestamp_secret,它存放在login界面中,登錄需要此參數
authenticity_token = re.findall('<input type="hidden" name="authenticity_token" value="(.*?)" />',
                                login_response.text,
                                re.S)[0]

timestamp_secret = re.findall('<input type="hidden" name="timestamp_secret" value="(.*?)" class="form-control" />',
                              login_response.text,
                              re.S)[0]

print(authenticity_token)
print(timestamp_secret)
form_data = {
    'commit': 'Sign in',
    'utf8': '✓',
    'authenticity_token': authenticity_token,
    'ga_id': '765496688.1577703239',
    'login': username,
    'password': password,
    'webauthn-support': 'supported',
    'webauthn-iuvpaa-support': 'unsupported',
    'required_field_ea03': '',
    'timestamp': 1577703901509,  # 時間戳
    'timestamp_secret': timestamp_secret
}

session_url = 'https://github.com/session'
session_response = requests.post(
    url=session_url,
    data=form_data,
    cookies=login_response.cookies,
    headers=header
)

emails_response = requests.get('https://github.com/settings/emails', cookies=session_response.cookies)
print('xxxx' in emails_response.text)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM