最新可用的goole翻译接口
1、 代码示例:
import requests
def translate(text, fromLang="auto", toLang="zh-CN"):
try:
url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=' + fromLang + '&tl=' + toLang + '&dt=t&q=' + text
data = requests.get(url).json()
return data[0][0][0]
except Exception as e:
print("goole API翻译接口异常")
return ''
if __name__ == '__main__':
print(translate("Good morning"))
2、输出结果
早上好