19.SimLogin_case03
2024-09-05 10:45:36
# 模拟登录GitHub
import requests
from lxml import etree
class Login():
def __init__(self):
self.headers = {
'Referer': 'https://github.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Host': 'github.com'}
self.login_url = 'https://github.com/login'
self.post_url = 'https://github.com/session'
self.logined_url = 'https://github.com/settings/profile'
self.session = requests.Session()
def token(self):
response = self.session.get(self.login_url, headers=self.headers)
selector = etree.HTML(response.text)
token = selector.xpath('//div//input[2]/@value')[0]
print('authenticity_token =', token)
return token
def login(self, email, password):
post_data = {
'commit': 'Sign in',
'utf8': '✓',
'authenticity_token': self.token(),
'login': email,
'password': password
}
response = self.session.post(
self.post_url,
data=post_data,
headers=self.headers)
print('login status code is:', response.status_code)
print(response.cookies.get_dict())
# print(response.url)
print('response header:', response.request.headers)
if response.status_code == 200:
self.repositories_name(response.text)
response = self.session.get(self.logined_url, headers=self.headers)
print('profile status code is:', response.status_code)
if response.status_code == 200:
self.logo(response.text)
def repositories_name(self, html):
selector = etree.HTML(html)
repositories_name = selector.xpath(
'//li[contains(@class, "public source")]/div[@class="width-full text-bold"]/a/span[2]/text()')
print(repositories_name)
def logo(self, html):
selector = etree.HTML(html)
logo_url = selector.xpath(
'//dl[contains(@class,"form-group")]/dd/img/@src')[0]
print('logo url is:', logo_url)
if __name__ == "__main__":
login = Login()
login.login(email='seancheney@qq.com', password='seancheney123')
最新文章
- SQL删除重复数据只保留一条
- thinkphp导入导出excel表单数据
- Unity3d游戏场景优化杂谈(4)
- app推送方案
- 重装Windows系统后,Linux系统启动引导失败
- 谷歌开源项目Chromium的源码获取与项目构建(Win7+vs10/vs13)
- 【BZOJ】【1221】【HNOI2001】软件开发
- 高性能MySql进化论(九):查询优化器常用的优化方式
- Hibernate的查询 HQL查询 查询某几列
- Selenium Grid跨浏览器-兼容性测试
- NGUI ScrollView动态加入和删除对象。
- 企业架构与建模之ArchiMate的由来和详述(上)
- mx51 IPU 透明处理
- solr5.5索引mysql数据(新手总结)
- Android Annotations(2)
- (三)图数据库neo4j的安装配置
- nginx部署django应用
- Jmeter 登入、新增、查询、修改、删除,动态传参。
- RabbitMQ 死信队列 延时
- 实例展示elasticsearch集群生态,分片以及水平扩展.