Python使用有道翻譯

import requests
content=input("請輸入:")
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
kv={
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
    }
data={'from': 'AUTO','to': 'AUTO','smartresult': 'dict','client': 'fanyideskweb','salt': '15720936967797','sign': '632f606ac7bfb3eb82c6d16642f1780e',
      'ts': '1572093696779','bv': 'f4d62a2579ebb44874d7ef93ba47e822','doctype': 'json','version': '2.1','keyfrom': 'fanyi.web','action': 'FY_BY_CLICKBUTTION'}
data['i']=content
r=requests.get(url,data,headers=kv,timeout=30).json()
print("翻譯結果爲:")
print(r['translateResult'][0][0]['tgt'])

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章