python 模擬登陸github的示例
# -*- coding: utf-8 -*-# @Author: CriseLYJ# @Date: 2020-08-14 12:13:11import reimport requestsclass 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的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. 基于PHP做個(gè)圖片防盜鏈2. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢(xún)、排序、分頁(yè)3. .NET中實(shí)現(xiàn)對(duì)象數(shù)據(jù)映射示例詳解4. jscript與vbscript 操作XML元素屬性的代碼5. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解6. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)7. XML在語(yǔ)音合成中的應(yīng)用8. 如何使用ASP.NET Core 配置文件9. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車(chē)輛管理系統(tǒng)10. ASP.NET MVC把數(shù)據(jù)庫(kù)中枚舉項(xiàng)的數(shù)字轉(zhuǎn)換成文字
