【问题标题】:How do I convert german words to english using Python? [closed]如何使用 Python 将德语单词转换为英语? [关闭]
【发布时间】:2015-05-02 06:49:19
【问题描述】:

我正在尝试抓取一个德语网站,我需要将抓取的数据从德语转换为英语。现在,我所做的是我已经访问了第三方网站来为我完成这个过程。在此我附上了我尝试过的代码如下:

from bs4 import BeautifulSoup, SoupStrainer
import urllib2
import urllib
import re
import sys
import string
import json
import socket


def translate(text_to_translate):
    base_url = 'http://translate.reference.com/german/english/'
    join_url = base_url + text_to_translate
    request = urllib2.Request(join_url)
    response = urllib2.urlopen(request)
    soup = BeautifulSoup(response)
    result = soup.find('textarea', {'placeholder': 'Translation'})
    converted_text = result.string
    return converted_text


text = "damen uhren"
text1 = re.sub('\s+', '-', text)
title_new = translate(text1)
print "Original String = ", text
print "Converted String = ", title_new

有没有办法在不访问第三方网站的情况下将德语字符串转换为英语?是的,请指导我完成此操作。

【问题讨论】:

标签: python non-english


【解决方案1】:

您可以使用 goslate(谷歌翻译 python api)。 首先,在终端,$pip install goslate

  import goslate
  gs = goslate.Goslate()
  new_word = gs.translate('my german sentence', 'de')

【讨论】:

  • 这需要向 Google 服务发出 HTTP 请求。因此,容易被屏蔽。
【解决方案2】:

goslate 已经承认谷歌翻译引入的票务系统。

“谷歌最近更新了它的翻译服务,增加了票证机制,以防止像 goslate 这样简单的爬虫程序访问。虽然更复杂的爬虫程序在技术上仍然可以工作,但是它已经越过了使用服务和破坏服务。goslate不会更新打破google的ticket机制。免费午餐结束。感谢使用。"

http://pythonhosted.org/goslate/

你可能对 py-translate 有一些运气。我不知道提供的翻译有多准确。很可能它使用字典。

https://pypi.python.org/pypi/py-translate

【讨论】:

  • py-translate 在其 git 页面上显示已弃用。 “由于 Google 协议条款的更改,此库已被弃用。请使用 Google Cloud Translation API”是否还有其他选择...
猜你喜欢
  • 1970-01-01
  • 2013-01-07
  • 1970-01-01
  • 1970-01-01
  • 2012-10-09
  • 2014-02-10
  • 2011-07-06
  • 2011-01-13
  • 1970-01-01
相关资源
最近更新 更多