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,测试成功

最新文章

  1. (转载)解决GDI闪烁
  2. final修饰符
  3. CentOS7 下 安装 supervisor以及使用
  4. 安装redis时遇到zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
  5. 【bzoj1857】 Scoi2010—传送带
  6. [工具]Mac平台开发几个网络抓包工具(sniffer)
  7. DRL之:策略梯度方法 (Policy Gradient Methods)
  8. ROM、RAM、DRAM、SRAM和FLASH区别
  9. JSONP(跨域请求) —— 一种非官方跨域数据交互协议
  10. extjs中gridpanel动态显示/隐藏列
  11. vector迭代器失效的一种情形
  12. Spark集群搭建步骤
  13. ML笔记:Classification: Logistic Regression
  14. “==”、“equals()”、“hashcode()”之间的秘密
  15. Haproxy官方文档翻译(第二章)配置Haproxy 附英文原文
  16. net core 2.0 + Autofac的坑
  17. ubuntu 使用旧式Gnome风格的菜单
  18. SpringBoot之OAuth2.0学习之客户端快速上手
  19. alios-things makefile
  20. 让IIS7和IIS6识别PUT和DELETE请求

热门文章

  1. 37、mysql初识
  2. 虚拟表dual。字符串函数UPPER,LOWER。&变量。INITCAP,LENGTH,SUBSTR
  3. Python学习日记:day9--------函数
  4. Java JTS & 空间数据模型
  5. bzoj 1179: [Apio2009]Atm
  6. bat获取系统时间修改系统密码
  7. LAMP第四部分mysql操作
  8. cd 命令详解
  9. swig官方go Examples 源码勘误
  10. Android 一排按钮居中显示