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

19.SimLogin_case03的更多相关文章

  1. Mediaplayer error (-19,0)

    Android MediaPlayer 发生 error (-19,0) 错误解决方法. 引起原因:由于多次实例化MediaPlayer.start() 进行播放操作引起的.由于没有及时释放内存资源导 ...

  2. 录像时调用MediaRecorder的start()时发生start failed: -19错误

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  3. CSharpGL(19)用glReadPixels把渲染的内容保存为PNG图片(C#)

    CSharpGL(19)用glReadPixels把渲染的内容保存为PNG图片(C#) 效果图 本文解决了将OpenGL渲染出来的内容保存到PNG图片的方法. 下载 CSharpGL已在GitHub开 ...

  4. ABP(现代ASP.NET样板开发框架)系列之19、ABP应用层——审计日志

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之19.ABP应用层——审计日志 ABP是“ASP.NET Boilerplate Project (ASP.NET ...

  5. js正则表达式校验非负浮点数:^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. js正则表达式校验非负整数:^\d+$ 或 ^[1-9]\d*|0$

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. js正则表达式校验非零的正整数:^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. C#开发微信门户及应用(19)-微信企业号的消息发送(文本、图片、文件、语音、视频、图文消息等)

    我们知道,企业号主要是面向企业需求而生的,因此内部消息的交流显得非常重要,而且发送.回复消息数量应该很可观,对于大企业尤其如此,因此可以结合企业号实现内部消息的交流.企业号具有关注安全.消息无限制等特 ...

  9. 19-typedef

    本文目录 一.typedef作用简介 二.typedef与指针 三.typedef与结构体 三.typedef与指向结构体的指针 四.typedef与枚举类型 五.typedef与指向函数的指针 六. ...

随机推荐

  1. 36. 解决线程问题方式一(同步代码块synchronized)

    解决线程问题: 方式一:同步代码块(synchronized) 语法: synchronized ("锁对象") {             //需要锁定的代码       }   ...

  2. wpf 解决 WPF SelectionChanged事件向上传递造成重复执行不想执行的函数的问题

    例如 tabcontrol里有一个tabitem tabitem里有一个combox和一个datagrid tabcontrol combox datagrid都有SelectionChanged事件 ...

  3. leetcood学习笔记-107-二叉树的层次遍历二

    题目描述: 方法一: class Solution(object): def levelOrderBottom(self, root): """ :type root: ...

  4. Nginx集群配置启动报错

  5. bzoj1012题解

    [解题思路] 强制在线线段树/树状数组,没什么好说的..复杂度O(mlog2m)(线段树)或O(mlog22m)(树状数组). [参考代码] (还naive的时候写的zkw真是翔..) #includ ...

  6. 矩阵乘法分配律+bitset优化——hdu4920

    因为是模3,所以把原矩阵拆成两个01矩阵,然后按分配律拆开分别进行矩阵乘法,行列用bitset来存进行优化即可 注意 int bitset<int>::count() 函数可以统计bits ...

  7. MetalLB自建私有Kubernetes的LoadBalancer负载均衡类型服务

    简介 在私有网络上运行 Kubernetes,和御三家相比,对 LoadBalancer 类型的服务的支持应该是众多表面差异中最醒目的一个了.类型为 LoadBalancer 的服务在 Kuberne ...

  8. NX二次开发-UFUN获取显示在NX交互界面的对象UF_OBJ_is_displayable

    NX9+VS2012 #include <uf.h> #include <uf_disp.h> #include <uf_obj.h> #include <u ...

  9. nginx按日分割日志

    #!/bin/bash #按日切割nginx日志并压缩,加入crontab每天0:00切割 #作者:fafu_li #时间: source /etc/profile #加载系统环境变量 source ...

  10. IntelliJ IDEA创建springboot项目

    1.创建新项目. 2. 3.Group 是包名,Artifact是项目名. 4.springboot版本尽量选择最高版本,且不要选择SNAPSHOP版本. 5.路径可自定义,默认为D://IDEA/M ...