1. 程式人生 > >爬有道翻譯

爬有道翻譯

url png imp pri response web 分享 譯文 輸入

import urllib.request
import urllib.parse
import json
content=input(‘請輸入你要翻譯文本\n‘)
data={}
data[‘i‘] = content
data[‘from‘] = ‘AUTO‘
data[‘to‘] = ‘AUTO‘
data[‘smartresult‘] = ‘dict‘
data[‘client‘] = ‘fanyideskweb‘
data[‘salt‘] = ‘f‘
data[‘sign‘] = ‘sign‘
data[‘doctype‘] = ‘json‘
data[‘version‘] = ‘2.1‘
data[‘keyfrom‘] = ‘fanyi.web‘
data[‘action‘] = ‘FY_BY_CL1CKBUTTON‘
data[‘typoResult‘] = ‘true‘
url=‘http://fanyi.youdao.com/translate‘
data=urllib.parse.urlencode(data).encode(‘utf-8‘)
request=urllib.request.Request(url=url,data=data)
response=urllib.request.urlopen(request)
html=response.read().decode(‘utf-8‘)
html=json.loads(html)
print(html[‘translateResult‘][0][0][‘tgt‘])

技術分享圖片

技術分享圖片

技術分享圖片



爬有道翻譯