• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

scrapy实现github登录

武飞扬头像
小木猿
帮助2

效果展示

学新通

  1.  
    import scrapy
  2.  
     
  3.  
     
  4.  
    class LoginSpider(scrapy.Spider):
  5.  
    name = 'login'
  6.  
    allowed_domains = ['github.com']
  7.  
    start_urls = ['http://github.com/login']#首先访问登录页面
  8.  
    P= "15175857475a"
  9.  
    def parse(self, response):
  10.  
    authenticity_token=response.xpath('//input[@name="authenticity_token"]/@value').extract()[0]
  11.  
    timestamp=response.xpath('//input[@name="timestamp"]/@value').extract()[0]
  12.  
    timestamp_secret=response.xpath('//input[@name="timestamp_secret"]/@value').extract()[0]
  13.  
    required_field=response.xpath('//input[@type="text"]/@name').extract()[1]
  14.  
    form_data={
  15.  
    "commit": "Sign in",
  16.  
    "authenticity_token":authenticity_token ,
  17.  
    "login": "用户名",
  18.  
    "trusted_device": "",
  19.  
    "password": "密码",
  20.  
    "webauthn-support": "supported",
  21.  
    "webauthn-iuvpaa-support": "unsupported",
  22.  
    "return_to": "https://github.com/login",
  23.  
    "allow_signup": "",
  24.  
    "client_id": "",
  25.  
    "integration": "",
  26.  
    required_field: "",
  27.  
    "timestamp": timestamp,
  28.  
    "timestamp_secret":timestamp_secret,
  29.  
    }
  30.  
    yield scrapy.FormRequest(url="http://github.com/session",callback=self.verify_login,formdata=form_data)
  31.  
    def verify_login(self,response):
  32.  
    if "Fengxiaobing00" in response.text:
  33.  
    print("登录成功")
  34.  
    else:
  35.  
    print("不成功")
  36.  
    #登录github
  37.  
    #请求流程 向 https://github.com/session 提交post 用户名密码等数据 获取登录页面
  38.  
    #1.访问 https://github.com/login获取https://github.com/session 需要的参数
  39.  
     
  40.  
    """commit: Sign in 忽略
  41.  
    需要购造
  42.  
    authenticity_token: qx0N300eRt thwVSihcr93xQOhYLRGsdEEBXf0twTZXS8lCV9e58/neVLLBY0/v1A7zAhASGyIeuJdSR28oBRA==
  43.  
    login: 2418917657@qq.com 用户名
  44.  
    password: 15175857475a1 密码
  45.  
    trusted_device:
  46.  
    webauthn-support: supported 忽略
  47.  
    webauthn-iuvpaa-support: unsupported 忽略
  48.  
    return_to: https://github.com/login
  49.  
    allow_signup:
  50.  
    client_id:
  51.  
    integration:
  52.  
    required_field_f9a9: 不太一样,但是没有数据
  53.  
    timestamp: 1641002690912 时间戳 需要枸造
  54.  
     
  55.  
    需要枸造
  56.  
    timestamp_secret: b539cdfd359669612d24768a002e4f3ccca2f52ccba8217aefc4eb6485ccf9f5"""
  57.  
     
  58.  
    """
  59.  
    参数获取的方式:
  60.  
    1.之前请求的页面中获取
  61.  
    2.js代码动态生成
  62.  
    """
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgceebe
系列文章
更多 icon
同类精品
更多 icon
继续加载