github免密登陆
import requests import re # 一:先获取登陆页面,拿到authenticity_token: # 1 请求的url:https://github.com/login # 2 请求方法:GET # 3 请求头: # User-Agent r1 = requests.get('https://github.com/login', headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', }, ) authenticity_token = re.findall('name="authenticity_token".*?value="(.*?)"', r1.text, re.S)[0] r1_cookies=r1.cookies.get_dict() print(authenticity_token) print(r1_cookies) # 二:提交表单数据完成登陆 # 1 请求的url:https://github.com/session # 2 请求方法:POST # 3 请求头: # Referer:https://github.com/ # User-Agent # 4 请求体 # commit:Sign in # utf8:✓ # authenticity_token:pFLyO9choCgUd6mm1AMP7BoeEQ613TRDe49MBREZ7EU7MKM7IELFgmyGfcKXS0hsaIiGJ8YlkTD5nwwV4tebig== # login:xxxxxxx@qq.com # password:xxxxxxx r2 = requests.post('https://github.com/session', headers={ "Referer": "https://github.com/", 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', }, cookies=r1_cookies, data={ "commit": "Sign in", 'utf8': "✓", "authenticity_token": authenticity_token, "login": "xxxxxx@qq.com", "password": "xxxxxxxx", }, allow_redirects=False ) # print(r2.status_code) # print(r2.history) cookies=r2.cookies.get_dict() r3=requests.get('https://github.com/settings/emails', headers={ "Referer": "https://github.com/", 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', }, cookies=cookies) print('xxxxxxx@qq.com' in r3.text) #返回true,测试成功
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/8290197.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)