import requests
from bs4 import BeautifulSoup
Gtoken = requests.get(
url="https://github.com/login"
#有时候注意模拟浏览器的行为,加上请求头
)
print("打开登陆页面状态",Gtoken.status_code)
TokenSoup = BeautifulSoup(Gtoken.text,"html.parser")
TokenValue = TokenSoup.find(name="input",attrs={"name":"authenticity_token"})
Cookies_list = Gtoken.cookies.get_dict()
SignIn = requests.post(
url="https://github.com/session",
data={
"commit":"Sign+in",
"utf8":"✓",
"authenticity_token":TokenValue.get("value"),
"login":"61****371@qq.com",
"password":"******"
},
cookies = Cookies_list
)
print("登陆账号状态",SignIn.status_code)
SignInSoup = BeautifulSoup(SignIn.text,"html.parser")
UserName = SignInSoup.find(name='strong',attrs={"class":"css-truncate-target"})
Cookies_Sigin = SignIn.cookies.get_dict()
Nameurl = "https://github.com/{0}".format(UserName.text)
UserPro = requests.get(
url = Nameurl,
cookies = Cookies_Sigin
)
print("打开个人主页状态",UserPro.status_code)
UserNameSoup = BeautifulSoup(UserPro.text,"html.parser")
UserName_gh = UserNameSoup.find(name="span",attrs={"class":"p-name vcard-fullname d-block overflow-hidden"})
print("获取个人信息之名字:",UserName_gh.text) #这里就简单地获取github中的名字
#print(SignInSoup)
用requests,BeautifulSoup模块获取Github的个人信息
最新推荐文章于 2024-06-05 11:10:27 发布