其他分享
首页 > 其他分享> > day_01 github访问

day_01 github访问

作者:互联网

import requests
import re
login_url='https://github.com/login'
login_header={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
}
login_res=requests.get(url=login_url,headers=login_header)
authenticity_token=re.findall(
    '<input type="hidden" name="authenticity_token" value="(.*?)" />',
    login_res.text,
    re.S
)[0]
print(authenticity_token)

login_cookies=login_res.cookies.get_dict()
session_url='https://github.com/session'
session_headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
}
form_data={
    "commit":"Sign in",
    "utf8":"✓",
    "authenticity_token":authenticity_token,
    "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)

 

标签:cookies,01,url,res,github,session,authenticity,login,day
来源: https://www.cnblogs.com/ZHKsuika/p/11116564.html