@
caneman 对, 我看教程的分析也是这样的, 关键的点就是时间戳和 md5, 但是这样用 python 写下来得到的返回值是 error 50, 我自己写的和之前教程上的代码都是这样。
```
# -*- coding: utf-8 -*-
# from lizhelib.scrapy_lizhe import *
import requests
import time
def str_MD5(origin_string):
import hashlib
m = hashlib.md5()
m.update(origin_string.encode('utf-8'))
return m.hexdigest()
keyword = "apple"
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en,zh-CN;q=0.9,zh;q=0.8,en-US;q=0.7',
'Connection': 'keep-alive',
'Content-Length': '237',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie': 'OUTFOX_SEARCH_USER_ID=-1113838040@106.119.72.215; OUTFOX_SEARCH_USER_ID_NCOO=1539804542.6380599; _ntes_nnid=063365ee317cb05d955f6037c9b7f99b,1562145610441; DICT_UGC=be3af0da19b5c5e6aa4e17bd8d90b28a|; JSESSIONID=abcKgh9yV1U-IdF1piKVw; ___rl__test__cookies={}'.format(int(round(time.time() * 1000, 0))),
'Host': '
fanyi.youdao.com',
'Origin': '
http://fanyi.youdao.com',
'Referer': '
http://fanyi.youdao.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}
salt_value = str(int(round(time.time() * 1000, 0))) + '1'
form_data = {
'i': 'live',
'from': 'AUTO',
'to': 'AUTO',
'smartresult': 'dict',
'client': 'fanyideskweb',
'salt': salt_value,
'sign': str_MD5("fanyideskweb" + keyword + salt_value + "97_3(jkMYg@T[KZQmqjTK"),
'ts': str(int(round(time.time() * 1000, 0))),
'bv': str_MD5(headers["User-Agent"]),
'doctype': 'json',
'version': '2.1',
'keyfrom': 'fanyi.web',
'action': 'FY_BY_REALTlME'
}
url = "
http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
response =
requests.post(url, headers=headers, data=form_data)
print(response.content)
```