|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
"""
Created on Mon Jun 29 15:25:26 2020
@author: Corvus
"""
import requests
from hashlib import md5
import time
import random
def fasong(x):
url="http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
headers={
'Accept': 'pplication/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'Connection': 'keep-alive',
'Content-Length': '239',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'OUTFOX_SEARCH_USER_ID=1879194388@10.169.0.102; OUTFOX_SEARCH_USER_ID_NCOO=1407266575.6763363; JSESSIONID=aaa09S_4yRwnccJhNw-lx; ___rl__test__cookies=1593422023525',
'Host': 'fanyi.youdao.com',
'Origin': 'http://fanyi.youdao.com',
'Referer': 'http://fanyi.youdao.com/',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
}
r = str(int(time.time()*1000))
i = r + str(random.randint(0, 9))
s = md5()
sign = "fanyideskweb" + x + i + "mmbP%A-r6U3Nw(n]BjuEU"
s.update(sign.encode())
sign = s.hexdigest()
print(x,'\n','\n',r,'\n',i,'\n',s.hexdigest(),'\n')
words={
'i': x,
'from': 'AUTO',
'to': 'AUTO',
'smartresult':' dict',
'client': 'fanyideskweb',
'salt': i,
'sign': s,
'ts': r,
'bv': '02a6ad4308a3443b3732d855273259bf',
'doctype': 'json',
'version': '2.1',
'keyfrom': 'fanyi.web',
'action': 'FY_BY_CLICKBUTTION',
}
result = requests.post(url, data=words, headers=headers)
print(result)
print(result.text)
if __name__ == '__main__':
fasong(input('需要翻译的词:'))
结果:
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.12.0 -- An enhanced Interactive Python.
runfile('D:/pyth/未命名0.py', wdir='D:/pyth')
需要翻译的词:go
go
1593428123294
15934281232945
f1a893db098ad88abc887481a068957e
<Response [200]>
{"errorCode":50}
对照了半天也不知道错哪了 |
|