码迷,mamicode.com
首页 > 其他好文 > 详细

有道翻译爬虫

时间:2016-05-15 13:53:46      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

import urllib.request
import urllib.parse
import json

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

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

data = {}
data[type] = AUTO
data[doctype] = json
data[i] = content
data[keyfrom] = fanyi.web
data[typoresult] = true
data[ue] = UTF-8
data[xmlVersion] = 1.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)

print(target[translateResult][0][0][tgt])

 

有道翻译爬虫

标签:

原文地址:http://www.cnblogs.com/wumac/p/5495101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!