初学者Python模拟登陆站点遇到问题

时间:2017-10-27 12:38:17

标签: python

我在模拟网站(www.yiban.cn)时遇到了一些问题,但无法模拟网站登陆。返回我的回复说帐号密码错误,使用RSA密码加密。 我的代码如下:

import requests
from Crypto.PublicKey import RSA
import base64
import json

url = 'https://www.yiban.cn/login'
r = requests.get(url)
html = r.content.decode('utf-8')
a = html.find('-----BEGIN PUBLIC KEY-----')
b = html.find('-----END PUBLIC KEY-----', a)
encrypwd = html[a:b+24]
a = html.find('data-keys-time')
b = html.find('>')
keysTime = html[a+16:b-1]
password = 'xxxxxxxxxxxxxxxxxxxxxx'

encryptor = RSA.importKey(encrypwd)
encrypData = encryptor.encrypt(password.encode('utf-8'), 0)
encrypData = base64.b64encode(encrypData[0])
encrypassword = bytes.decode(encrypData)

login_data = {
    'account':'xxxxxxxxxxxxxxxxxxxx',
    'password':encrypassword,
    'captcha':'',
    'keysTime':keysTime,
}

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
    'Connection':'keep-alive',
}
headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
headers['X-Requested-With'] = 'XMLHttpRequest'

login_url = 'https://www.yiban.cn/login/doLoginAjax'
session = requests.session()
content = session.post(url=login_url, headers=headers, data=login_data)
print(json.loads(content.text))

0 个答案:

没有答案
相关问题