爬有道翻译
Posted 马老师的大弟子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬有道翻译相关的知识,希望对你有一定的参考价值。
import urllib.request
import urllib.parse
import json
content=input(\'请输入你要翻译文本\\n\')
data={}
data[\'i\'] = content
data[\'from\'] = \'AUTO\'
data[\'to\'] = \'AUTO\'
data[\'smartresult\'] = \'dict\'
data[\'client\'] = \'fanyideskweb\'
data[\'salt\'] = \'f\'
data[\'sign\'] = \'sign\'
data[\'doctype\'] = \'json\'
data[\'version\'] = \'2.1\'
data[\'keyfrom\'] = \'fanyi.web\'
data[\'action\'] = \'FY_BY_CL1CKBUTTON\'
data[\'typoResult\'] = \'true\'
url=\'http://fanyi.youdao.com/translate\'
data=urllib.parse.urlencode(data).encode(\'utf-8\')
request=urllib.request.Request(url=url,data=data)
response=urllib.request.urlopen(request)
html=response.read().decode(\'utf-8\')
html=json.loads(html)
print(html[\'translateResult\'][0][0][\'tgt\'])
以上是关于爬有道翻译的主要内容,如果未能解决你的问题,请参考以下文章