参考大牛
使用谷歌翻译的python 的api的时候,很多时候都会有对于ip的限制,比如翻译几十条语句就会被禁,所以应该使用如下代码
try:
translation=translator.translate(content,des);
return translation.text
except:
print("第一次翻译失败")
translator=Translator()
try:
translation=translator.translate(content,des);
return translation.text
except:
return ''
在每次不可以翻译后,重新实例化一个翻译对象,在进行翻译
另外如果使用代理,时延会很严重,所以可以考虑修改源代码cilent.py,gtoken.py,urls.py
把translate.google.com 替换为 translate.google.cn
如果不知道代码在哪里,可以在安装完googletrans之后,在使用 pip install googletrans,来查看