有道爬虫失败,想大家求教
import urllib.requestimport 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) 有道反爬了,试试加上User-Agent 本帖最后由 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",我就动了这里
FC的注册很坑 发表于 2018-9-7 13:45
试试这个?就把xmlVersion改成version,然后我这边是成功的
第7行"version" : "1.6",我就动了这里
成功了 感谢!
页:
[1]