qsyy216 发表于 2022-5-25 20:59:58

请指点哪里错了。

import urllib.request
import urllib.parse
import json

content = input("请输入需要翻译的内容:")

url = "https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"
date = {}
date['i'] = content
date['from']= 'AUTO'
date['to'] = 'AUTO'
date['smartresult'] = 'dict'
date['client'] = 'fanyideskweb'
date['salt'] = '16534004642201'
date['sign'] = 'f5415463234c0a7142cf086486c5606b'
date['lts'] = '1653400464220'
date['bv'] = '889515d40c155c78bec0e862ef4395b8'
date['doctype'] = 'json'
date['version'] = '2.1'
date['keyfrom'] = 'fanyi.web'
date['action'] = 'FY_BY_CLICKBUTTION'

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

target = json.loads(html)
print("翻译结果:%s" % (target['translateResult']['tgt']))

isdkz 发表于 2022-5-25 21:14:07

本帖最后由 isdkz 于 2022-5-28 10:10 编辑

import urllib.request
import urllib.parse
import json

content = input("请输入需要翻译的内容:")

url = "https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"          # 改了这里
date = {}
date['i'] = content
date['from']= 'AUTO'
date['to'] = 'AUTO'
date['smartresult'] = 'dict'
date['client'] = 'fanyideskweb'
date['salt'] = '16534004642201'
date['sign'] = 'f5415463234c0a7142cf086486c5606b'
date['lts'] = '1653400464220'
date['bv'] = '889515d40c155c78bec0e862ef4395b8'
date['doctype'] = 'json'
date['version'] = '2.1'
date['keyfrom'] = 'fanyi.web'
date['action'] = 'FY_BY_CLICKBUTTION'

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

target = json.loads(html)
print("翻译结果:%s" % (target['translateResult']['tgt']))

qsyy216 发表于 2022-5-28 10:10:06

isdkz 发表于 2022-5-25 21:14


还是不对。

isdkz 发表于 2022-5-28 10:11:26

qsyy216 发表于 2022-5-28 10:10
还是不对。

你的 url 用了中文问号

import urllib.request
import urllib.parse
import json

content = input("请输入需要翻译的内容:")

url = "https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"          # 改了这里
date = {}
date['i'] = content
date['from']= 'AUTO'
date['to'] = 'AUTO'
date['smartresult'] = 'dict'
date['client'] = 'fanyideskweb'
date['salt'] = '16534004642201'
date['sign'] = 'f5415463234c0a7142cf086486c5606b'
date['lts'] = '1653400464220'
date['bv'] = '889515d40c155c78bec0e862ef4395b8'
date['doctype'] = 'json'
date['version'] = '2.1'
date['keyfrom'] = 'fanyi.web'
date['action'] = 'FY_BY_CLICKBUTTION'

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

target = json.loads(html)
print("翻译结果:%s" % (target['translateResult']['tgt']))
页: [1]
查看完整版本: 请指点哪里错了。