测试人社区

爬取有道词典的翻译内容,在执行中返回ErrorcCoder=50,请大神帮忙看一下咋回事

‘’’
import urllib.request
import urllib.parse
url = ‘http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule
data = {}
data[“i”] = “明天去一下医院”
data[“from”] = “AUTO”
data[“to”] = “AUTO”
data[“datesmartresult”] = “dict”
data[“client”] = “fanyideskweb”
data[“salt”] = “15913260390103”
data[“sign”] = “2f6a10fae10c21c7b58003b28a066b80”
data[“ts”] = “1591326039010”
data[“bv”] = “bae4fb40b166eb91e4fbab5cdd840d79”
data[“doctype”] = “json”
data[“version”] = “2.1”
data[“keyfrom”] =“fanyi.web”
data[“action”] = “FY_BY_CLICKBUTTION”
head = {}
head[‘User-Agent’] = ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36’

data = urllib.parse.urlencode(data).encode(‘utf-8’)

req = urllib.request.Request(url,data,head)

response = urllib.request.urlopen(req)

html = response.read().decode(‘utf-8’)

print(html)
‘’’

你直接访问 你上面 的 url 看看页面显示的什么?

image

把 URL 换成

http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule
1 Like

如果有代码,注意格式化代码,参考答疑区置顶帖