python 模擬登陸github的示例
更新時間:2020年12月04日 16:28:21 作者:Kr1s77
這篇文章主要介紹了python 模擬登陸github的示例代碼,幫助大家更好的理解和學(xué)習(xí)python 爬蟲的相關(guān)知識,感興趣的朋友可以了解下
# -*- coding: utf-8 -*-
# @Author: CriseLYJ
# @Date: 2020-08-14 12:13:11
import re
import requests
class GithubLogin(object):
def __init__(self, email, password):
# 初始化信息
self.headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
'Referer': 'https://github.com/',
'Host': 'github.com'
}
self.session = requests.Session()
self.login_url = 'https://github.com/login'
self.post_url = 'https://github.com/session'
self.email = email
self.password = password
def login_GitHub(self):
# 登錄入口
post_data = {
'commit': 'Sign in',
'utf8': '✓',
'authenticity_token': self.get_token(),
'login': self.email,
'password': self.password
}
resp = self.session.post(
self.post_url, data=post_data, headers=self.headers)
print('StatusCode:', resp.status_code)
if resp.status_code != 200:
print('Login Fail')
match = re.search(r'"user-login" content="(.*?)"', resp.text)
user_name = match.group(1)
print('UserName:', user_name)
# Get login token
def get_token(self):
response = self.session.get(self.login_url, headers=self.headers)
if response.status_code != 200:
print('Get token fail')
return None
match = re.search(
r'name="authenticity_token" value="(.*?)"', response.text)
if not match:
print('Get Token Fail')
return None
return match.group(1)
if __name__ == '__main__':
email = input('Account:')
password = input('Password:')
login = GithubLogin(email, password)
login.login_GitHub()
登錄效果

以上就是python 模擬登陸github的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于python 模擬登陸github的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python GUI庫圖形界面開發(fā)之PyQt5布局控件QHBoxLayout詳細(xì)使用方法與實(shí)例
這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5布局控件QHBoxLayout詳細(xì)使用方法與實(shí)例,需要的朋友可以參考下2020-03-03
Python實(shí)現(xiàn)向PPT中插入表格與圖片的方法詳解
這篇文章將帶大家學(xué)習(xí)一下如何在PPT中插入表格與圖片以及在表格中插入內(nèi)容,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-05-05
Python Pygame實(shí)戰(zhàn)之超級炸彈人游戲的實(shí)現(xiàn)
如今的玩家們在無聊的時候會玩些什么游戲呢?王者還是吃雞是最多的選擇。但在80、90年代的時候多是一些很簡單的游戲:《超級瑪麗》、《魂斗羅》等。本文將利用Pygame制作另一個經(jīng)典游戲—炸彈人,感興趣的可以了解一下2022-03-03
利用PyInstaller將python程序.py轉(zhuǎn)為.exe的方法詳解
這篇文章主要給大家介紹了利用PyInstaller將python程序.py轉(zhuǎn)為.exe的方法,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-05-05
python統(tǒng)計mysql數(shù)據(jù)量變化并調(diào)用接口告警的示例代碼
這篇文章主要介紹了python統(tǒng)計mysql數(shù)據(jù)量變化并調(diào)用接口告警的示例代碼,幫助大家更好的利用python操作數(shù)據(jù)庫,感興趣的朋友可以了解下2020-09-09

