更新时间:2023-02-24 20:08:44
如评论中所述,github使用发布数据进行身份验证,因此您应该在
As mentioned in the comments, github uses post data for authentication so you should have your creds in the data
parameter.
The elements you have to submit are 'login'
, 'password'
, and 'authenticity_token'
. The value of 'authenticity_token'
is dynamic, but you can scrape it from '/login'
.
Finally submit data
to /session
and you should have an authenticated session.
s = requests.Session()
r = s.get('https://www.github.com/login')
tree = html.fromstring(r.content)
data = {i.get('name'):i.get('value') for i in tree.cssselect('input')}
data['login'] = username
data['password'] = password
r = s.post('https://github.com/session', data=data)