wulljy 发表于 2018-9-2 16:22:04

有道爬虫失败,想大家求教

import urllib.request
import urllib.parse

sentence=input("d")
url= 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc'
data={}
data={"type":"AUTO", "i" : sentence, "doctype" : "json","xmlVersion" : "1.6", "keyfrom" : "fanyi.web","ue" : "UTF-8", "typoResult" : "true"}
data=urllib.parse.urlencode(data).encode('utf-8')

response=urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')

print(html)

dong628 发表于 2018-9-2 18:36:02

有道反爬了,试试加上User-Agent

FC的注册很坑 发表于 2018-9-7 13:45:22

本帖最后由 FC的注册很坑 于 2018-9-7 13:46 编辑

试试这个?就把xmlVersion改成version,然后我这边是成功的
import urllib.request
import urllib.parse

sentence=input("d")
url= 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc'
data={}
data={"type":"AUTO", "i" : sentence, "doctype" : "json","version" : "1.6", "keyfrom" : "fanyi.web","ue" : "UTF-8", "typoResult" : "true"}
data=urllib.parse.urlencode(data).encode('utf-8')

response=urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')

print(html)
第7行"version" : "1.6",我就动了这里

跳跳糖和摄魂怪 发表于 2018-9-8 10:08:51

FC的注册很坑 发表于 2018-9-7 13:45
试试这个?就把xmlVersion改成version,然后我这边是成功的

第7行"version" : "1.6",我就动了这里

成功了 感谢!
页: [1]
查看完整版本: 有道爬虫失败,想大家求教