python登陆github
#!/usr/bin/env python
# encoding: utf-8
import requests
from headers import headers
from lxml import html
from config import *
class Login(object):
def __init__(self):
headers["Referer"] = 'https://github.com/'
headers["Host"] = 'github.com'
self.login_url="https://github.com/login"
self.post_url="https://github.com/session"
self.headers=headers
self.session=requests.Session()
def get_token(self):
response=self.session.get(self.login_url,timeout=5)
if response.status_code==requests.codes.ok:
root = html.fromstring(response.text)
token = root.xpath("//input[@name='authenticity_token']/@value")[0]
if token:
return token
return False
def lgoin(self):
token=self.get_token()
if token:
data = {"commit": "Sign in", "utf8": "✓", "authenticity_token": token, "login":LOGIN_ID ,
"password": PASS_WORD} response = self.session.post(url=self.post_url, headers=headers, data=data, timeout=15)
print(response.text)
else:
print("获取token失败,登录失败")
if __name__=="__main__":
Login().lgoin()
#其中authenticity_token的值,位于一个隐藏的input标签中,另外headers需要传入的信息不止要有ua,还有
headers["Referer"] = 'https://github.com/'
headers["Host"] = 'github.com'
python登陆github的更多相关文章
- 爬虫【自动登陆github和抽屉】
自动登陆github用户详情页 代码 #! /usr/bin/env python # -*- coding: utf- -*- # __author__ = "wuxiaoyu" ...
- 基于 Python 官方 GitHub 构建 Python 文档
最近在学 Python,所以总是在看 Python 的官方文档, https://docs.python.org/2/ 因为祖传基因的影响,我总是喜欢把这些文档保存到本地,不过 Python 的文档实 ...
- python-爬虫之requests模块介绍(登陆github)
介绍 使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) 注意 requests库发送请求将网页内容下载下来以后 ...
- ssh登陆github
ssh [转载] 如果只是在一个仓库里管理文件历史,Git和SVN真没啥区别.为了保证你现在所学的Git物超所值,将来绝对不会后悔,同时为了打击已经不幸学了SVN的童鞋,本章开始介绍Git的杀手级功能 ...
- Python登陆人人网
#!coding:utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,password): #登 ...
- 利用Python模拟GitHub登录
最近学习了Fiddler抓包工具的简单使用,通过抓包,我们可以抓取到HTTP请求,并对其进行分析.现在我准备尝试着结合Python来模拟GitHub登录. Fiddler抓包分析 首先,我们想要模拟一 ...
- Python 爬虫四 基础案例-自动登陆github
GET&POST请求一般格式 爬取Github数据 GET&POST请求一般格式 很久之前在讲web框架的时候,曾经提到过一句话,在网络编程中“万物皆socket”.任何的网络通信归根 ...
- Python爬虫教程:requests模拟登陆github
1. Cookie 介绍 HTTP 协议是无状态的.因此,若不借助其他手段,远程的服务器就无法知道以前和客户端做了哪些通信.Cookie 就是「其他手段」之一. Cookie 一个典型的应用场景,就是 ...
- python模拟登陆Github示例
首先进入github登录页:https://github.com/login 输入账号密码,打开开发者工具,在Network页勾选上Preserve Log(显示持续日志),点击登录,查看Sessio ...
随机推荐
- [CodeForces948C]Producing Snow(优先队列)
Description 题目链接 Solution 将温度做一个前缀和,用一个优先队列依次处理一遍 思路还是很简单的 Code #include <cstdio> #include < ...
- linpack_2
Run linpack in server 1.Get computer nodal information lscpu dmidecode -t memory | head -45 | tail - ...
- 利用HttpClient测试
import java.io.IOException;import java.security.cert.CertificateException;import java.security.cert. ...
- 11 Django组件-分页器
Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views here ...
- BZOJ [Poi2012]Fibonacci Representation
找最近的数 记忆化 (我也不知道为什么对的) #include<cstdio> #include<algorithm> #include<map> using na ...
- 《1024伐木累-周末特别篇》-中彩票了,开发APP
本周发布的<1024伐木累>,受到了很多码汪们的好评,博主在这里感谢大家的支持,同时,博主临时起意,增加一期周末对话特别篇,让大家在“满血复活”的时间里,充分感受快乐的味道~ 1.中彩票 ...
- iOS笔记061 - 二维码的生成和扫描
二维码 生成二维码 二维码可以存放纯文本.名片或者URL 生成二维码的步骤: 导入CoreImage框架 通过滤镜CIFilter生成二维码 1.创建过滤器 2.恢复滤镜的默认属性 3.设置内容 4. ...
- ptmalloc,tcmalloc和jemalloc内存分配策略研究 ? I'm OWen..
转摘于http://www.360doc.com/content/13/0915/09/8363527_314549949.shtml 最近看了glibc的ptmaoolc,Goolge的tcmall ...
- SDK接入注意点
1. 新建的android项目,要把MainActivity.java里生成的东西全部删去,最好只留个onCreate入口方法,不然会产生什么“hello world”,会把自己写的View内的东西覆 ...
- LDA和PCA降维的原理和区别
LDA算法的主要优点有: 在降维过程中可以使用类别的先验知识经验,而像PCA这样的无监督学习则无法使用类别先验知识. LDA在样本分类信息依赖均值而不是方差的时候,比PCA之类的算法较优. LDA算 ...