|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import urllib.parse
import json
sentence = input("请输入要翻译的内容: ")
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc'
data = {}
data['type'] = 'AUTO'
data['i'] = sentence
data['doctype'] = 'json'
data['xmlVersion'] = '1.8'
data['keyfrom'] = 'fanyi.web'
data['ue'] = 'UTF-8'
data['action'] = 'FY_BY_CLICKBUTTION'
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']))
请输入要翻译的内容: python
翻译结果:您的请求来源非法,商业用途使用请关注有道翻译API官方网站“有道智云”: http://ai.youdao.com
这是不是就是因为非人类访问被检测到了,所以被拦截了
怎么绕过去呢
加上User-Agent,后面为你的系统版本号,浏览器信息等,审查网页可以看到
|
|