zoukankan      html  css  js  c++  java
  • 有道翻译API

    有道翻译API使用起来非常简单。给定参数,发送请求,即可拿到结果。

    # -*- coding: utf-8 -*-
    # author: huihui
    # date: 2020/2/21 5:19 下午 
    import requests
    
    url = "http://fanyi.youdao.com/translate"
    
    
    def get_trans(line):
        data = {
            'doctype': 'json',
            'type': 'AUTO',
            'i': line
        }
        r = requests.get(url, params=data)
        result = r.json()
        print(result)
    
    
    line = '安徽省亳州市漆园街道花园村,排列有序的光伏成为乡村一道靓丽的风景。近年来,安徽省亳州市蒙城县漆园街道通过与光伏发电企业及农业企业合作,建成运行40MW光伏发电项目,并建设290栋农业设施大棚,将太阳能发电与设施农业有机结合,实现棚顶光伏发电、棚内设施种植蔬菜、中药材等,最大限度发挥光伏电站的效益,不仅为当地农民增加收入,壮大村级集体经济,助力乡村振兴。'
    get_trans(line)
    

    返回结果:

    {'type': 'ZH_CN2EN', 'errorCode': 0, 'elapsedTime': 116, 'translateResult': [
            [
                {'src': '安徽省亳州市漆园街道花园村,排列有序的光伏成为乡村一道靓丽的风景。', 'tgt': 'Anhui province bozhou city paint garden street garden village, an orderly photovoltaic become village a beautiful beautiful scenery.'
                },
                {'src': '近年来,安徽省亳州市蒙城县漆园街道通过与光伏发电企业及农业企业合作,建成运行40MW光伏发电项目,并建设290栋农业设施大棚,将太阳能发电与设施农业有机结合,实现棚顶光伏发电、棚内设施种植蔬菜、中药材等,最大限度发挥光伏电站的效益,不仅为当地农民增加收入,壮大村级集体经济,助力乡村振兴。', 'tgt': 'In recent years, the anhui province bozhou city mengcheng paint garden street through cooperation with photovoltaic power generation enterprises and agricultural enterprises, the running 40 mw photovoltaic power generation project, and to build 290 greenhouses of agricultural facilities, the organic combination of solar and facility agriculture, the roof photovoltaic, relative facility cultivation of vegetables, medicinal herbs, etc., the maximum play to the benefit of the photovoltaic power station, not only for the local farmers to increase income, strengthen the village-level collective economy, boost rural revitalization.'
                }
            ]
        ]
    }
    

    可以看到,API内部会进行分句。所以,如果是多个句子的话,需要重新join一下结果中的tgt。

    本文仅供学习使用

  • 相关阅读:
    背景颜色的渐变设置--实现丰富多彩的背景效果
    CSS-sprit 雪碧图
    背景图片的相关设置
    关于阿里云图标的使用 iconfont
    HTML四种定位-粘滞定位
    HTML四种定位-固定定位
    HTML四种定位-绝对定位
    HTML四种常见的定位-相对定位
    水平居中
    CentOS8更换国内镜像源
  • 原文地址:https://www.cnblogs.com/xuehuiping/p/15185897.html
Copyright © 2011-2022 走看看