포스트 요청 자동 착륙 GitHub의

포스트 요청 자동 착륙 GitHub의

URL : https://github.com/session

신청 방법 : 포스트

请求 头 '사용자 에이전트': '모질라 / 5.0 (윈도우 NT 10.0; WOW64) AppleWebKit / 537.36 (게코 같은 KHTML) 크롬 / 75.0.3770.100 사파리 / 537.36'

요청 본문 :

  1. 커밋 : 로그인

  2. UTF8 : ✓

  3. authenticity_token :

    ZVmXUBJA / KD5HBTsezlAPy / TwSivooXI2G6yiRkTjlZv2BvlYd8FL4XCVGIXpijMMN00 / 2Xf7SWc2iuqo0DzSA ==

  4. 로그인: ******

  5. 암호 : ******

  6. webauthn 지원 : 지원

1. 임의의 문자열 토큰을 얻습니다

URL : https://github.com/login

신청 방법 : 취득

요청 헤더 :

이름 = "authenticity_token"값 = "+ K + NjPJaMzAs07qMDF1WumVvAwUE0wDYobB4izS7fJMEhYu J5RM1hEgw4417ysZqRM40lv69XsUoqrvulIxZ3w ==

코드 구현

import requests
import re
login_url='https://github.com/login'
#login页面的请求头
login_header={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
login_res=requests.get(url=login_url,headers=login_header)

print(login_res)

#解析提取token
authenticiyt_token = re.findall(
    'input type="hidden" name="authenticity_token" value="(.*?)" />',
    login_res.text,
    re.S
)[0]
print(authenticiyt_token)

2. 시작 Github에서 방문

# session登录url
session_url = 'https://github.com/session'

# 请求头信息
session_headers = {
    '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'

}

# 请求体信息
form_data = {
    "commit": "Sign in",
    "utf8": "✓",
    "authenticity_token": authenticity_token,
    "authenticity_token": "ZVmXUBJA/KD5HBTsezlAPy/TwSivooXI2G6yiRkTjlZv2BvlYd8FL4XCVGIXpijMMN00/2Xf7SWc2iuqo0DzSA==",
    "login": "*****",
    "password": "*****",
    "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)

추천

출처www.cnblogs.com/Crystal-Zh/p/11116423.html