import os
import time
if __name__ == '__main__':
import requests
from lxml import etree
# error_file
error_files = []
# 打开文件加
i = 0
# 切换目录
os.chdir(os.path.join(os.getcwd(),'文件夹'))
imgs = os.listdir(os.getcwd())
for i in imgs:
try:
title = os.path.splitext(i)[0]
title_fix = os.path.splitext(i)[1]
youdao_url = 'http://m.youdao.com/translate'
result = requests.post(url=youdao_url, data={'inputtext': title, "type": "AUTO"})
html_element = etree.HTML(result.text)
title = html_element.xpath('//*[@id="translateResult"]/li/text()')[0]
os.rename(i,title+title_fix)
print('修改文件:{}-----成功'.format(i))
time.sleep(2)
except:
error_files.append(i)
print('修改错误的文件')
print(error_files)
# youdao_url = 'http://m.youdao.com/translate'
# result = requests.post(url=youdao_url, data={'inputtext': ['hello','world'], "type": "AUTO"})
# html_element = etree.HTML(result.text)
# print(html_element.xpath('//*[@id="translateResult"]/li/text()')[0])
翻译并修改文件名
最新推荐文章于 2023-11-12 15:37:14 发布