脚本专栏 
首页 > 脚本专栏 > 浏览文章

python 模拟登陆github的示例

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )
# -*- 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的资料请关注其它相关文章!

上一篇:pymongo insert_many 批量插入的实例
下一篇:python 写一个文件分发小程序
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网