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)
  • 相关阅读:
    python字典推导式
    什么是Python 自省
    类变量和实例变量
    Python 使用正则表达式匹配URL网址
    python is 和 “==”的区别
    阮一峰老师的bash教程,建议阅读
    python里的闭包
    什么是生成器
    python访问限制
    pytorch使用Tips
  • 原文地址:https://www.cnblogs.com/ldq1996/p/8306023.html
Copyright © 2011-2022 走看看