[英]Google translate in python
使用來自https://stackabuse.com/text-translation-with-google-translate-api-in-python/的代碼時
from googletrans import Translator
translator = Translator()
result = translator.translate("Mitä sinä teet")
print(result.src)
print(result.dest)
print(result.origin)
print(result.text)
我得到 'AttributeError: 'NoneType' object has no attribute 'group'',我想知道出了什么問題,錯誤似乎在 'result = tra...' 行,
感謝您的任何幫助
好的,我也遇到了同樣的錯誤。 我認為當前版本存在問題。 但是新的 alpha 版本運行良好。
首先卸載當前版本:
pip uninstall googletrans
然后安裝這個:
pip install googletrans==3.1.0a0
with open(os.path.join(files_from_folder, filename), encoding='utf-8') as html:
soup = BeautifulSoup('<pre>' + html.read() + '</pre>', 'html.parser')
for title in soup.findAll('title'):
recursively_translate(title)
請參閱這 2 個完整的代碼,可以使用 python 輕松翻譯文件:
或者
https://neculaifantanaru.com/en/example-python-google-translate-any-text-html-file-version-2.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.