python通过docx模块解决doc及docx后缀文件内容的处理
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,import os,shutil,docx,re,timefrom win32com import client as wc#从所有级联目录读取文件到指定目录内def count_files(file
千家信息网最后更新 2025年12月02日python通过docx模块解决doc及docx后缀文件内容的处理
import os,shutil,docx,re,timefrom win32com import client as wc#从所有级联目录读取文件到指定目录内def count_files(file_dir): count=0 for p,d,f in os.walk(file_dir): for c in f: if c.split('.')[-1]=="doc": count +=1 src_dir = os.path.join(p, c) print(src_dir) dst_dir = file_dir + "back" if not os.path.exists(dst_dir): os.makedirs(dst_dir) shutil.copy(src_dir, dst_dir) return count#提取每个docx简历文档里面的邮箱地址,我们这里使用python-docx模块来解决pip install python-docxdef count_mail(file_dir,dst_file): mail_list = [] for parent,dirctiory,files in os.walk(file_dir): for f in files: doc = docx.Document(os.path.join(parent,f)) pattern = re.compile(r'''([a-zA-Z0-9._%+-]+@[a-zA-Z0-9\t\s.-]+(\.[a-zA-Z0-9\t\s]{2,4}))''', re.VERBOSE) for para in doc.paragraphs: for groups in pattern.findall(para.text): mail_list.append(groups[0].replace(" ","")+";") with open(dst_file,'w')as f: f.writelines(mail_list) print("=====================邮件信息写入成功===================")#由于python-docx模块只能处理docx后缀,我们需要处理doc后缀的文件,必须通过win32com模块来把doc后缀转换成docxdef docxTodoc(old_doc,new_doc): word = wc.Dispatch('Word.Application') for parent,directory,files in os.walk(old_doc): for f in files: doc = word.Documents.Open(os.path.join(parent,f)) # 目标路径下的文件 new_filepath=os.path.join(new_doc,f.split(".")[0]+".docx") print(new_filepath) doc.SaveAs(new_filepath, 12, False, "", True, "", False, False, False,False) # 转化后路径下的文件 doc.Close() print(time.time()) word.Quit()if __name__ == '__main__': print(count_files(r"C:\Users\icestick\Desktop\51job_导出简历_20180917")) count_mail(r"C:\Users\icestick\Desktop\new_doc",r"C:\Users\icestick\Desktop\test.txt" ) old_doc = r"C:\Users\icestick\Desktop\51job_导出简历_20180917" #需要把doc目录转成docx格式的原目录 new_doc = r"C:\Users\icestick\Desktop\new_doc" #需要把doc目录转成docx格式的目标目录 mail_extract = r"C:\Users\icestick\Desktop\test.txt" #邮箱提取好的文件 if not os.path.exists(new_doc): os.mkdir(new_doc) print("=====================目录创建成功======================") docxTodoc(old_doc, new_doc) print("=====================docx格式转换成功===================") count_mail(new_doc, mail_extract) else: docxTodoc(old_doc, new_doc) print("=====================docx格式转换成功===================") count_mail(new_doc, mail_extract)
目录
文件
成功
格式
后缀
模块
简历
处理
目标
路径
邮箱
信息
地址
文档
邮件
内容
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
东莞新华互联网科技学校
软件开发调试工资
es数据库搭建
越秀区光纤网络技术开发工艺
邯郸大数据软件开发哪家实惠
怎么看连接的服务器的文件夹
吐鲁番新华互联网科技行情
国内随访数据库
数据库信息安全排查
网络是一种单纯的网络技术
开展网络安全专项检查的方案
怎样查网络安全密钥
阿里巴巴公司网络技术
大数据时代软件开发模式
数据库地图化建设实施方案
mhxx数据库
手机软件开发大全
网络安全账户被掏空
进行网络安全的评估方法
网络安全的股票属于什么板块
服务器的龙蛋
海口大河互联网科技有限公司
hp2000服务器更换硬盘配置
网络是一种单纯的网络技术
4年级网络安全教育稿
长沙财务软件开发代码
公安厅外聘网络安全专家
密码学与网络安全专业是做什么的
服务器共享扫描功能
怎么找软件开发者