python模拟登陆steam

用python 模拟了steam登陆,下一步打算尝试着读取库存信息

import sys
sys.path.append(r'E:\anaconda\Lib\site-packages')
import requests
import time
import rsa
import base64
import execjs
from Crypto.Cipher import PKCS1_v1_5
import ssl
import time

get_rsakey_url = 'https://store.steampowered.com/login/getrsakey/'
login_url = 'https://store.steampowered.com/login/dologin/' 
login_headers = {
    'Referer':'https://store.steampowered.com/login/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
}

req = requests.session()
sign_dict = {'account_incorrect_sign':1,'guard_fail_sign':1}


def get_login_rsakey():
    #第一次输入账号密码错误后,会被置0,应该在开始置1 
    sign_dict['guard_fail_sign'] = 1                    
    
    username = input('input your steam account number:')
    password = input('input your steam account password:')
    
    data = {
    'donotcache':str(int(time.time()*1000)),
    'username':username
    }
    getkey_html = req.post(get_rsakey_url,data=data,headers=login_headers).json()    
    pub_mod = getkey_html.get('publickey_mod')
    pub_exp = getkey_html.get('publickey_exp')
    timestamp = getkey_html.get('timestamp')
#加密密码    RSA
    with open('rsa.js',encoding='utf-8') as f:
        jsdata = f.read()
    password_encrypt = execjs.compile(jsdata).call('getpwd',password,pub_mod,pub_exp)
    return username,password_encrypt,timestamp  
   
def login_request(_data_):
    login_data = {'donotcache':str(int(time.time()*1000)),
        'username':_data_[0],
        'password':_data_[1],
        'twofactorcode':'',
        'emailauth':'',
        'loginfriendlyname':'',
        'captchagid':'-1',
        'captcha_text':'',
        'emailsteamid':'',
        'rsatimestamp':_data_[2],
        'remember_login':'false',
        }
    
    response_data = req.post(login_url,data=login_data,headers=login_headers).json() 
    print('\nlogin_html\n',response_data)
    return response_data,login_data

def input_guard_number(_data_):
    html_data = _data_[0]
    login_data = _data_[1]
#没有手机令牌的账号,在输入过邮箱令牌一次后可以直接登录
    if (html_data.get('success') == True) and (html_data.get('login_complete') == True):
        sign_dict['guard_fail_sign'] = 0
        sign_dict['account_incorrect_sign']= 0
        return html_data
#没有手机令牌,第一次登录需要邮箱验证码
    elif html_data.get('emailauth_needed') == True:
        email_guard_number = input('input the email guard number:')
        login_data['twofactorcode'] = email_guard_number 
        sign_dict['account_incorrect_sign']= 0
        return req.post(login_url, data=login_data, headers=login_headers).json()
#输入手机令牌
    elif (html_data.get('success') == False) and (html_data.get('message') == ''):
        phone_guard_number = input('input the phone guard number:')
        login_data['twofactorcode'] = phone_guard_number
        sign_dict['account_incorrect_sign']= 0
        return req.post(login_url, data=login_data, headers=login_headers).json()
#输入账号密码错误
    elif (html_data.get('success') == False) and (html_data.get('message') == 'The account name or password that you have entered is incorrect.'):
        sign_dict['guard_fail_sign'] = 0
        print('\nthe input incorrect !!! try again\n')
        
#判断是否登录成功
def if_login_successful(login_with_guard_html):
    if login_with_guard_html != None:       
        if (login_with_guard_html.get('success') == True) and (login_with_guard_html.get('login_complete') == True):
            sign_dict['guard_fail_sign'] = 0
            print('\nsuccessfully login')   

if __name__ == '__main__':
#账号密码错误,重新输入账号密码
    while(bool(sign_dict['account_incorrect_sign'])):
        data = get_login_rsakey() 
        data2 = login_request(data)
#令牌输入错误,重新输入令牌
        while(bool(sign_dict['guard_fail_sign'])):
            html_data = input_guard_number(data2)
            if_login_successful(html_data)
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值