Loading

最新可用的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、输出结果

早上好

posted @ 2021-05-10 12:45  Roc-xb  阅读(17)  评论(0编辑  收藏  举报

易微帮源码


易微帮官网