我是靠谱客的博主 默默摩托,这篇文章主要介绍Python调用有道翻译API学习目标:学习内容:学习产出:,现在分享给大家,希望可以做个参考。

学习目标:

今天使用的googletrans包由于官方升级,导致程序异常,苦寻方案良久,所以写一个替代方案以备不时之需


学习内容:

设计一个googletrans替代方案


学习产出:

使用有道翻译进行替代:

# -*- coding:utf-8 -*-
import requests

def fanyiyoudao():
    string = """
    A leading Peruvian regulator has stated that the coronavirus pandemic will not derail the government’s plans to 
    regulate the nation’s crypto industry – and has claimed “monitoring” of Peru-based crypto exchanges has already 
    begun.Per Gestión, Sergio Espinosa, the head of the top financial regulatory body, the Superintendencia de Banca, 
    Seguros y AFP (SBS)’s Financial Intelligence Unit, said that the virus would not delay his organization’s work.
    """
    data = {
        'doctype': 'json',
        'type': 'AUTO',
        'i': string
    }
    url = "http://fanyi.youdao.com/translate"
    r = requests.get(url, params=data)
    result = r.json()
    print(result['translateResult'][1][0]['tgt'])
    res = result['translateResult'][1][0]['tgt']
    return res


fanyiyoudao()

翻译结果:

秘鲁主要监管机构表示,冠状病毒大流行不会破坏政府的计划调节国家的加密行业,声称“监控”的广播加密交流已经开始了。

翻译的效果还是可以的。????????????

最后

以上就是默默摩托最近收集整理的关于Python调用有道翻译API学习目标:学习内容:学习产出:的全部内容,更多相关Python调用有道翻译API学习目标内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(124)

评论列表共有 0 条评论

立即
投稿
返回
顶部