|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请输入要翻译的内容:love
{'errno': 997, 'errmsg': '未知错误', 'query': 'love', 'from': 'en', 'to': 'zh', 'error': 997}
代码
import urllib.request
import urllib.parse
import json
while True:
content = input('请输入要翻译的内容:')
url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
date = {}
date['query']=content
date['domain']='common'
date['from']='en'
date['sign']='682950.952567'
date['simple_means_flag']= 3
date['to']='zh'
date['token']='c9c1a05ce811848d5ef65ec86bd7a822'
date['transtype']='realtime'
date = urllib.parse.urlencode(date).encode('utf-8')
response = urllib.request.urlopen(url,date)
html = response.read().decode('utf-8')
target = json.loads(html)
print(target)
target = target["trans_result"]["data"][0]["dst"]
print(target)
|
|