求指导!!!!!!
import requests
while True:#实现多次翻译过程
url = 'https://fanyi.baidu.com/sug'#sug作为翻译爬取到的search engine
import tkinter as tk
window = tk.Tk() # 建立窗口window
window.title('翻译内容') # 窗口名称
window.geometry("400x400") # 窗口大小(长*宽)
textExample = tk.Text(window, height=10) # 创建文本输入框
textExample.pack() # 把Text放在window上面,显示Text这个控
def getTextInput():
result = textExample.get("1.0", "2.0")
print(result) # 输出结果
return result
btnRead = tk.Button(window, height=1, width=10, text="Read", command=getTextInput) # command绑定获取文本框内容的方法
btnRead.pack() # 显示按钮
window.mainloop() # 显示窗口
dat = {
'kw':result
}#数据储存到名为的字典之中从!!!!!!!!!!!!!此处result报错未定义
resp = requests.post(url,data=dat)
resp.close()
#将爬取到的内容转格式为json()
print(resp.json())
- 复制链接
- 举报