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的示例代碼的詳細內(nèi)容,更多關(guān)于python 模擬登陸github的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于Python socket的端口掃描程序?qū)嵗a
這篇文章主要介紹了基于Python socket的端口掃描程序?qū)嵗a,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下2018-02-02利用python實現(xiàn)簡單的郵件發(fā)送客戶端示例
下面小編就為大家分享一篇利用python實現(xiàn)簡單的郵件發(fā)送客戶端示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12Windows中安裝使用Virtualenv來創(chuàng)建獨立Python環(huán)境
有時我們的程序中需要調(diào)用不同版本的Python包和模塊,那么借助Virtualenv的虛擬環(huán)境就可以幫助我們隔離使用,接下來我們就來看一下在Windows中安裝使用Virtualenv來創(chuàng)建獨立Python環(huán)境的方法2016-05-05Ubuntu16.04 安裝多個python版本的問題及解決方法
Ubuntu16.04自帶python2.7與python3.5,Ubuntu 官方 apt 庫中還未收錄 python 3.8,因此添加 deadsnakes PPA 源安裝python3.8,否則會出現(xiàn)報錯,接下來通過本文給大家介紹Ubuntu16.04 安裝python的問題,一起看看吧2021-09-09Python成功解決ZeroDivisionError:?division?by?zero的方法過程
在Python編程中,ZeroDivisionError:divisionbyzero是因為嘗試除以零所導(dǎo)致的常見錯誤,這篇文章詳細介紹了錯誤的原因、解決方案,需要的朋友可以參考下2024-09-09PyCharm 2021.2 (Professional)調(diào)試遠程服務(wù)器程序的操作技巧
本文給大家分享用 PyCharm 2021 調(diào)試遠程服務(wù)器程序的過程,通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2021-08-08