项目地址:  https://github.com/ssut/py-googletrans

安装:

sudo pip install googletrans

使用:

#!/usr/bin/python
# coding: UTF-8
import sys
reload(sys)
sys.setdefaultencoding('UTF-8')
from googletrans import Translator
translator = Translator()
print translator.translate('co-founder', dest='zh-CN',src='en')

结果:

/usr/bin/python2.7 /home/dahu/PycharmProjects/SpiderLearning/pytorch_lianxi/gugeapi.py
Translated(src=en, dest=zh-cn, text=联合创始人, pronunciation=None) Process finished with exit code 0

本来想直接构造查询单词的url地址,但是在爬取的时候获取不到那个值,里面有个tk值不知道.

看了下源码又修改了一下:

#!/usr/bin/python
# coding: UTF-8
import sys
reload(sys)
sys.setdefaultencoding('UTF-8')
from googletrans import Translator
translator = Translator()
with open('tmp1','r') as f:
for line in f:
# print translator.translate('co-founder', dest='zh-CN',src='en')
a=translator.translate(line, dest='zh-CN',src='en')
print line.strip(),getattr(a,"text")
Segmentation 分割
Motivation 动机
evaluate 评估
Perplexity 困惑 Process finished with exit code 0

直接提取所翻译的字

谷歌翻译python接口的更多相关文章

  1. python爬虫调用谷歌翻译接口

    2019年7月4日15:53:17 (¦3[▓▓] 晚安 谷歌翻译环境 Python 3.6 第三方库 Execjs (pip install PyExecJS ) 文件列表 同目录下的四个文件: - ...

  2. Python3 动手自己写谷歌翻译

    本篇为实现谷歌翻译的功能,在编写的时候以为只是一个接口的问题. 没想到的是每次翻译都会触发一次JS的执行,在请求参数中生成一个tk. 文中tk的实现是复用的网上大神的代码生成tk. 好了,不说了直接看 ...

  3. php 调用python接口出现的一系列问题(原)

    调用示例代码(python写的一个谷歌翻译接口): $name = '中国'; exec("/mob360/EditImage/venv/bin/python /EditImage/fany ...

  4. C#实现谷歌翻译API

    由于谷歌翻译官方API是付费版本,本着免费和开源的精神,分享一下用C#实现谷歌翻译API的代码.这个代码非常简单,主要分两块:通过WebRequest的方式请求内容:获取Get方式的请求参数(难点在于 ...

  5. python接口自动化20-requests获取响应时间(elapsed)与超时(timeout)

    前言 requests发请求时,接口的响应时间,也是我们需要关注的一个点,如果响应时间太长,也是不合理的. 如果服务端没及时响应,也不能一直等着,可以设置一个timeout超时的时间 关于reques ...

  6. ubuntu16.04 安装caffe以及python接口

    http://blog.csdn.net/qq_25073253/article/details/72571714http://blog.csdn.net/greed7480/article/deta ...

  7. QuantLib 金融计算——自己动手封装 Python 接口(2)

    目录 QuantLib 金融计算--自己动手封装 Python 接口(2) 概述 如何封装一项复杂功能? 寻找最小功能集合的策略 实践 估计期限结构参数 修改官方接口文件 下一步的计划 QuantLi ...

  8. caffe的python接口学习(7):绘制loss和accuracy曲线

    使用python接口来运行caffe程序,主要的原因是python非常容易可视化.所以不推荐大家在命令行下面运行python程序.如果非要在命令行下面运行,还不如直接用 c++算了. 推荐使用jupy ...

  9. StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?

    StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...

随机推荐

  1. poj1659 Frogs' Neighborhood

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10239   Accepted: 4 ...

  2. 「CSS」css基础

    1. 文字水平居中 将一段文字置于容器的水平中点,只要设置text-align属性即可: text-align:center; 2. 容器水平居中 先该容器设置一个明确宽度,然后将margin的水平值 ...

  3. 生存分析/Weibull Distribution韦布尔分布

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&am ...

  4. JS零碎小知识

    filter()方法对数组进行过滤,生成新数组 var aqiNewData = aqiData.filter(function(data){ return data[1]>60; }); // ...

  5. 【BZOJ】4358: permu 莫队算法

    [题意]给定长度为n的排列,m次询问区间[L,R]的最长连续值域.n<=50000. [算法]莫队算法 [题解]考虑莫队维护增加一个数的信息:设up[x]表示数值x往上延伸的最大长度,down[ ...

  6. 基本控件文档-UITableView---iOS-Apple苹果官方文档翻译

    //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3496969.html 技术博客http://www.cnblogs.com/ChenYi ...

  7. CodeForces 990B

    You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, u ...

  8. Spring Tool Suite 配置和使用

    Spring Tool Suite使用 1.下载地址: http://spring.io/tools 2.配置字符编码:UTF-8 默认的编码是ISO-8859-1的西欧文字编 1.windows-- ...

  9. jQuery实现简单前端搜索功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 福建工程学院寒假作业第一周F题

    Subsequence TimeLimit:1000MS  MemoryLimit:65536K 64-bit integer IO format:%lld   问题描述: A sequence of ...