鱼C论坛

 找回密码
 立即注册
查看: 1430|回复: 1

[已解决]通过代码使用有道翻译,输出结果有问题

[复制链接]
发表于 2021-7-13 16:48:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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},不明白哪里出了问题
最佳答案
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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-14 02:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表