python调用谷歌翻译Googletrans接口

慕承允
2023-12-01

1. 使用场景

快速翻译一些爬取的英文文章或段落

2. pip install

pip install googletrans

3. 调用

3.1 英译汉

from googletrans import Translator

#实例化
translator = Translator(service_urls=['translate.google.cn'])

content = 'Today is a gooday'

transed_content = translator.translate(content, dest='zh-CN').text

print(transed_content)

3.2 汉译英

from googletrans import Translator

translator = Translator()
print(translator.translate('星期日').text)

4. 参考

https://www.jianshu.com/p/0f2d3619c377
https://www.jianshu.com/p/2f9a2b4c3aa3

 类似资料: