PYTHON-채널 기반 온라인 번역

import urllib.request
import urllib.parse
import json
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict2.index'  #       
data={'type':'AUTO',#           
	'i':'I love you',
	'doctype':'json',
	'xmlVersion':'1.8',
	'keyfrom':'fanyi.web',
	'ue':'UTF-8',
	'action':'FY_BY_CLICKBUTTON',
	'typoResult':'true'}
str=input('        ')#       
data['i']= str#     
data =urllib.parse.urlencode(data).encode('utf-8')#urllib.parse.urlencode(data)         ,     str( )
response = urllib.request.urlopen(url,data)#         
html=response.read().decode('utf-8')#    utf-8  ,     json
html=json.loads(html)#     
print(html["translateResult"][0][0]["tgt"])#  

좋은 웹페이지 즐겨찾기