kygschp 发表于 2021-7-13 16:48:45

通过代码使用有道翻译,输出结果有问题

import urllib.request
import urllib.parse

url = "https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"

data = {}
data['i'] = 'i love python'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16260996240444'
data['sign'] = '463117c612697bad2114f4258f015b75'
data['lts'] = '1626099624044'
data['bv'] = '5b3e307b66a6c075d525ed231dcc8dcd'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')

response = urllib.request.urlopen(url, data)
content =response.read().decode('utf-8')

print(content)





{"errorCode":50}



小白求助,按照小甲鱼教的步骤,通过代码使用有道翻译,但是输出的内容是{"errorCode":50},不明白哪里出了问题

Twilight6 发表于 2021-7-14 08:08:01


url 中的 _o 去掉即可,这是有到反爬给的假链接,参考代码:

import urllib.request
import urllib.parse

url = "https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"

data = {}
data['i'] = 'i love python'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16260996240444'
data['sign'] = '463117c612697bad2114f4258f015b75'
data['lts'] = '1626099624044'
data['bv'] = '5b3e307b66a6c075d525ed231dcc8dcd'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')

response = urllib.request.urlopen(url, data)
content =response.read().decode('utf-8')

print(content)
页: [1]
查看完整版本: 通过代码使用有道翻译,输出结果有问题