import requests
from bs4 import BeautifulSoup
import pymongo
client=pymongo.MongoClient(host="localhost",port=27017)
db=client.errorword
collection=db.English
true=1
while true==1:
word = input("请输入你所要翻译语句")
errorword={}
if word=="0":
true=0
else:
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
key = {
"i": word,
"from": "AUTO",
"to": "AUTO",
"smartresult": "dict",
"client": "fanyideskweb",
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"action": "FY_BY_REALTIME",
"typoResult": "true"
}
html = requests.post(url, data=key)
js = html.json()
result=js['translateResult'][0][0]['tgt']
print("翻译结果:" +result+ '\n')
errorword[word]=result
collection.insert(errorword)
# soup=BeautifulSoup(html.content,"html.parser")
# print(soup)