爬取有道翻译进行翻译
学习小甲鱼的爬虫之后做的爬取有道翻译进行翻译,废话不多说直接上代码。import urllib.request
import urllib.parse
import json
import time
while True:
content = input("请输入要翻译的内容:(输入”q!”退出程序):")
if content == "q!":
break
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult"
head = {}
head['User.Agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36"
data = {}
data["i"] = content
data["from"] = "AUTO"
data["to"] = "AUTO"
data["smartresult"] = "dict"
data["client"] = "fanyideskweb"
data["salt"] = "15981872159194"
data["sign"] = "cfd7bc0ad5a9d4433c3ff54e338c61f9"
data["lts"] = "1598187215919"
data["bv"] = "4b1009b506fa4405f21e207abc4459fd"
data["doctype"] = "json"
data["version"] = "2.1"
data["keyfrom"] = "fanyi.web"
data["action"] =" FY_BY_REALTlME"
data = urllib.parse.urlencode(data).encode("utf-8")
response = urllib.request.urlopen(url,data)
html = response.read().decode("utf-8")
target = json.loads(html)
print("翻译结果:%s"%(target["translateResult"]["tgt"]))
time.sleep(5) 谁能给我提点建议 sign 怎么找的
页:
[1]