zoukankan      html  css  js  c++  java
  • 使用requests进行模拟登陆

    import re
    import requests
    
    header = {
        'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1",
        'Referer': 'https://passport.lagou.com/login/login.html',
        }
    
    session = requests.session()
    r1 = session.get('https://passport.lagou.com/login/login.html',
                     headers=header
                     )
    X_Anti_Forge_Token = re.findall(r"X_Anti_Forge_Token = '(.*?)'", r1.text)[0]
    X_Anti_Forge_Code = re.findall(r"X_Anti_Forge_Code = '(.*?)'", r1.text)[0]
    
    # X-Anit-Forge-Code:45530844
    # X-Anit-Forge-Token:7f50218e-0796-46bc-9190-1fbe6790cf56
    # X-Requested-With:XMLHttpRequest
    
    header2 = header['X-Anit-Forge-Code'] = X_Anti_Forge_Code
    header['X-Anit-Forge-Token'] = X_Anti_Forge_Token
    
    # print(header2)
    
    session.post('https://passport.lagou.com/login/login.json',
                 headers=header,
                 data={
                     'isValidate': True,
                     'username': '18611453110',
                     'password': '70621c64832c4d4d66a47be6150b4a8e',
                     'request_form_verifyCode': '',
                     'submit': '',
                 },
                 )
    
    
    
    r3=session.get('https://passport.lagou.com/grantServiceTicket/grant.html',
                headers={
                    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
                    'Referer': 'https://passport.lagou.com/login/login.html',
                }
                )
    
    #第四步:验证
    r4=session.get('https://www.lagou.com/resume/myresume.html',
                   headers={
                       'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
                   }
                   )
    
    print('18611453110' in r4.text)
    
    
    
    r6 = session.post('https://www.lagou.com/jobs/companyAjax.json',
                 headers = header,
                 params = {
    
                 },
                      data={
    
                      }
                 )
    
    
    
    print(r6.text)
  • 相关阅读:
    [JZOJ3339]【NOI2013模拟】wyl8899和法法塔的游戏
    [JZOJ3337] 【NOI2013模拟】wyl8899的TLE
    UVA 1262 Password
    UVA 10820 Send a Table
    UVA 12716 GCD XOR
    UVA 10791
    UVA 10375 choose and divide (唯一分解定理)
    欧拉函数
    51 Nod 1069 Nim游戏
    51 Nod 1242 矩阵快速幂求斐波那契数列
  • 原文地址:https://www.cnblogs.com/ldq1996/p/8306023.html
Copyright © 2011-2022 走看看