Google 翻译 API Python

Google Translate API Python

我在使用 Google 翻译 API 时遇到了一些问题。

示例;

翻译本文标题时:

http://vtimes.com.au/dua-xe-f1-thu-ngua-chien-bat-them-benh-2622229.html

(Đua xe F1: Thử "ngựa chiến" bắt thêm bệnh)

引号返回为 "

当使用 translate.google.com 时,它显然会如您所愿地返回。

我是不是漏掉了一些编码之类的东西(?)啊!帮助:D

代码片段:

service = build('translate', 'v2',
                 developerKey=self.config['google-api']['dev-key'])
    try:
        title = (service.translations().list(
            source=source,
            target='en',
            q=text
        ).execute())['translations'][0]['translatedText']
    except (KeyError, IndexError):
        return text
    return title

有一个简单的解决方案。 html 包挽救了局面。

import html

service = ...
   ...
...

return html.unescape(title)