小甲鱼的爬虫爬有道翻译2019可用操作,关于小甲鱼爬虫的问题。

errorCode:50,url = 中translate_o?后面的“_o”去掉就好了

import urllib.request
import urllib.parse
import json

content = input("请输入待翻译的内容:")
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"

head = {}
head['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'

data = {}
data['type'] = 'AUTO'
data['i'] = content
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom']= 'fanyi.web'
data['typoResult'] = 'false'
data['ue']= 'utf-8'
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')

target = json.loads(html)
target = target['translateResult'][0][0]['tgt']

print(req.headers)
print(target)

结果是这样的
讲道理没问题
就这样8。。。还有问题的就没办法了,技不如人,甘拜下风。

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页