|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import urllib.parse
import json
from tkinter import *
x, y = 0, 0
tk = Tk()
tk.title("网易有道翻译")
tk.geometry("840x400")
tk.maxsize(840, 600)
Label(tk, text="有道翻译", font=("微软雅黑", 16)).place(x=100, y=80, anchor="w")
left = Entry(tk)
left.place(x=200, y=160, anchor="n")
var = left.get()
right = Entry(tk)
right.place(x=600, y=160, anchor="n")
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
data = {}
data['type'] = " AUTO'"
data['i'] =var
data['doctype'] = 'json'
data[' xmlVersion'] = '1.6'
data['keyfrom'] = " fanyi.web"
data['ue'] = 'UTF-8'
data['typoResult'] = ' true'
data = urllib.parse.urlencode(data).encode("utf-8")
reponse = urllib.request.urlopen(url, data)
html = reponse.read().decode("utf-8")
target = json.loads(html)
fanyi = target["translateResult"][0][0]["tgt"]
right.insert(0,fanyi)
mainloop()
错误异常
Traceback (most recent call last):
File "D:/python/untitled/youdao.py", line 41, in <module>
target = json.loads(html)
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 27 (char 26) |
|