python 模拟登陆github的示例

(编辑:jimmy 日期: 2024/9/21 浏览:2)

# -*- 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': '"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的示例

以上就是python 模拟登陆github的示例代码的详细内容,更多关于python 模拟登陆github的资料请关注其它相关文章!

一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。