# 模拟登录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')

最新文章

  1. SQL删除重复数据只保留一条
  2. thinkphp导入导出excel表单数据
  3. Unity3d游戏场景优化杂谈(4)
  4. app推送方案
  5. 重装Windows系统后,Linux系统启动引导失败
  6. 谷歌开源项目Chromium的源码获取与项目构建(Win7+vs10/vs13)
  7. 【BZOJ】【1221】【HNOI2001】软件开发
  8. 高性能MySql进化论(九):查询优化器常用的优化方式
  9. Hibernate的查询 HQL查询 查询某几列
  10. Selenium Grid跨浏览器-兼容性测试
  11. NGUI ScrollView动态加入和删除对象。
  12. 企业架构与建模之ArchiMate的由来和详述(上)
  13. mx51 IPU 透明处理
  14. solr5.5索引mysql数据(新手总结)
  15. Android Annotations(2)
  16. (三)图数据库neo4j的安装配置
  17. nginx部署django应用
  18. Jmeter 登入、新增、查询、修改、删除,动态传参。
  19. RabbitMQ 死信队列 延时
  20. 实例展示elasticsearch集群生态,分片以及水平扩展.

热门文章

  1. vue+elementui 中 @keyup 键盘上下左右移动聚焦
  2. join加入线程
  3. hibernate(一对多关系)
  4. csp-s模拟测试92
  5. POJ2226-Muddy Fields-二分图*
  6. python爬虫教程之美丽汤(一)
  7. BackgroundWorker study
  8. Spring源码由浅入深系列三 refresh
  9. 安装mongo
  10. 第三天:字典表dict、元组tuple、文件与类型汇总