标签:== apple sla user 封装 any sign lse tkinter
用python爬虫可以制作英语翻译小工具。来看下代码吧~import requests,json
#函数封装
def translator():
session=requests.session()
i=input(‘请问你要翻译什么?‘)
url=‘http://fanyi.youdao.com/translate‘
headers={
‘Referer‘: ‘http://fanyi.youdao.com/‘,
‘User-Agent‘: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36‘
}
data={
‘i‘: i,
‘from‘: ‘AUTO‘,
‘to‘: ‘AUTO‘,
‘smartresult‘: ‘dict‘,
‘client‘: ‘fanyideskweb‘,
‘salt‘: ‘15679333317663‘,
‘sign‘: ‘9079899a595e5c8f8888629378b30b7f‘,
‘ts‘: ‘1567933331766‘,
‘bv‘: ‘557ba5b86a7d3547c6067a0f7b462c5b‘,
‘doctype‘: ‘json‘,
‘version‘: ‘2.1‘,
‘keyfrom‘: ‘fanyi.web‘,
‘action‘: ‘FY_BY_REALTlME‘
}
result=session.post(url,headers=headers,data=data).text
# print(type(result))
result_dic=json.loads(result)
# print(type(result_dic))
tgt=result_dic[‘translateResult‘][0][0][‘tgt‘]
print(tgt)
while True:
translator()
choose=str(input(‘请问你是否继续翻译?选择Y或者N‘))
if choose==‘Y‘:
continue
else:
break
print(‘翻译结束!‘)
使用tkinter功能还可以制作成本地窗口,下次再展示吧~
标签:== apple sla user 封装 any sign lse tkinter
原文地址:https://blog.51cto.com/14534896/2436596