冷月谷 发表于 2018-4-2 18:10:19

零基础入门python第054课爬虫有道翻译失败

import urllib.request as ur
import urllib.parse as up
import json

url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc'


data = {
      "type" : "AUTO",
      "i" : 'hello',
      "doctype" : "json",
      "xmlVersion" : "1.8",
      "keyfrom" : "fanyi.web",
      "ue" : "UTF-8",
      "action" : "FY_BY_CLICKBUTTON",
      "typoResult" : "true"}
data = up.urlencode(data).encode('utf-8')

response = ur.urlopen(url, data)
html = response.read().decode('utf-8')
target = json.loads(html)

print(target)


运行结果是

{'type': 'EN2ZH_CN', 'errorCode': 30, 'elapsedTime': 0, 'translateResult': [[{'src': '您的请求来源非法,商业用途使用请关注有道翻译API官方网站“有道智云”: http://ai.youdao.com', 'tgt': '您的请求来源非法,商业用途使用请关注有道翻译API官方网站“有道智云”: http://ai.youdao.com'}]]}

冷月谷 发表于 2018-4-2 18:11:19

请问怎么才能做到爬出翻译结果,谢谢

冷月谷 发表于 2018-4-2 18:13:08

我是出现error:50错误后按照这个链接的回答做的http://bbs.fishc.com/thread-86581-1-1.html

ba21 发表于 2018-4-2 18:54:53

您的请求来源非法,商业用途使用请关注有道翻译API官方网站
说得很清楚了,反爬就得先解密。
练习还是换网站吧。
页: [1]
查看完整版本: 零基础入门python第054课爬虫有道翻译失败