最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 模擬登陸github的示例

 更新時(shí)間:2020年12月04日 16:28:21   作者:Kr1s77  
這篇文章主要介紹了python 模擬登陸github的示例代碼,幫助大家更好的理解和學(xué)習(xí)python 爬蟲的相關(guān)知識(shí),感興趣的朋友可以了解下
# -*- 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的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

吐鲁番市| 长岛县| 同江市| 白山市| 甘德县| 彰武县| 托克托县| 甘泉县| 石林| 武川县| 石林| 砚山县| 浦县| 开封市| 宝山区| 青海省| 光泽县| 景宁| 华蓥市| 天柱县| 丰镇市| 雅安市| 灵武市| 肇州县| 高唐县| 荔波县| 永胜县| 江源县| 辽源市| 临海市| 余庆县| 师宗县| 高尔夫| 阜平县| 高雄市| 石家庄市| 靖安县| 宁陵县| 桂东县| 龙川县| 建德市|