废话不多说,直接上代码
import urllib.request import urllib.parse import json content = input("请输入要翻译的内容:") url = ‘http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null‘ data = {} data[‘type‘] = ‘AUTO‘ data[‘i‘] = content data[‘doctype‘] = ‘json‘ data[‘xmlVersion‘] = ‘1.8‘ data[‘keyfrom‘] = ‘fanyi.web‘ data[‘ue‘] = ‘UTF-8‘ data[‘action‘] = ‘FY_BY_CLICKBUTTON‘ data[‘typoResult‘] = ‘true‘ 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‘][0][0][‘tgt‘]))
友情提示:不要多用,会被屏蔽的哈(博友们可以出个招,看看怎么隐藏自己,不被屏蔽)
本文出自 “IT--小哥” 博客,请务必保留此出处http://402753795.blog.51cto.com/10788998/1793631
原文地址:http://402753795.blog.51cto.com/10788998/1793631