爬虫自动登陆GitHub
import requests from bs4 import BeautifulSoup r1 = requests.get( url=\'https://github.com/login\' ) s1 = BeautifulSoup(r1.text, \'html.parser\') token = s1.find(name=\'input\', attrs={\'name\': \'authenticity_token\'}).get(\'value\') # 取到token值 r1_cookie_dict = r1.cookies.get_dict() r2 = requests.post( url=\'https://github.com/session\', data={ \'commit\':\'Sign in\', \'utf8\':\'✓\', \'authenticity_token\':token, \'login\':\'1439286684@qq.com\', \'password\':\'123456\' # 要输入正确的账号密码 }, cookies=r1_cookie_dict ) r2_cookie_dict = r2.cookies.get_dict() r3 = requests.get( url=\'https://github.com/settings/emails\', cookies=r2_cookie_dict ) # 如果打印的内容带有登陆用户的信息就是登陆成功了 print(r3.text)
版权声明:本文为aaronthon原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。