Switch to python.exe In the directory .
python -m pip install googletrans==4.0.0-rc1 -i https://mirrors.aliyun.com/pypi/simple/
See blog https://plugin.blog.csdn.net/article/details/124514912
take Html Copy in txt file ,Python Reading data , Call Google translation engine , Finally save to file . Note that the string length cannot exceed 5000 word .
from googletrans import Translator
# Set up Google Translation service address
translator = Translator(service_urls=[
'translate.google.cn'
])
def ReadFile(filename):
ff=None;
with open(filename, 'r') as f:
ff = f.read();
return ff;
def WriteFile(filename,data):
# Open a file
fo = open(filename, "w");
fo.write(data);
# Close open files
fo.close();
htmlStr=ReadFile(r"C:\Users\ajz\Desktop\html.txt");
translation = translator.translate(htmlStr, dest='zh-CN');
print(translation.text);
WriteFile(r"C:\Users\ajz\Desktop\htmlrlt.txt",translation.text);
If you have any questions , Please leave a message .