import zipfile
import re
from win32com import client as wc #导入模块
import os
import pymysql
#将doc转化为docx.因docx为压缩包,自带html文件
def doc_to_docx(file):
word = wc.Dispatch("Word.Application") # 打开word应用程序
doc = word.Documents.Open(file) #打开word文件
doc.SaveAs("{}x".format(file), 12)#另存为后缀为".docx"的文件,其中参数12指docx文件
doc.Close() #关闭原来word文件
word.Quit()
print(file.split('/')[-1]+"完成!")
return "{}x".format(file)
def get_document(filepath):
z = zipfile.ZipFile(filepath, "r")
text = z.read("word/document.xml").decode("UTF-8")
text = re.sub(r"<.*?>", "", text)#去除xml里的所有标记符
return text
if __name__ == '__main__':
file_path= 'C:/Users/lenovo/Desktop/other/简历/长亮数据-咨询部笔试题目-附件'
for filename in os.listdir(file_path):
if filename.split('.')[-1] != 'docx':
fp = doc_to_docx(file_path+'/'+filename)
page_text = get_document(fp)
print(page_text)
# 性别
sex = re.findall(r"目前正在找工作 (.*?) | | 现居住", page_text, re.S)[0]
if len(sex) <1:
sex = 'null'
# 年龄
age = re.findall(r"现居住 .*? | (.*?)年工作经验最近工作", page_text, re.S)[0].split('|')[1]
if len(age) <1:
age = 'null'
# 地址
dress = re.findall(r"现居住 .*? | (.*?)年工作经验最近工作", page_text, re.S)[0].split('|')[2].strip().split(' ')[-1]
if dress == '现居住':
dress = 'null'
# 工作年龄
work_age = re.findall(r"现居住 .*? | (.*?)年工作经验最近工作", page_text, re.S)[0].split('|')[-1]
if len(work_age) <1:
work_age = 'null'
# 职位
work_name = re.findall(r"职 位:(.*?)公 司:行 业", page_text, re.S)[0]
if len(work_name) <1:
work_name = 'null'
# 公司
company_name = re.findall(r"公 司:(.*?)行 业", page_text, re.S)[0]
if len(company_name) <1:
company_name= 'null'
# 行业
industry_name = re.findall(r"职 位:(.*?)公 司:行 业", page_text, re.S)[0]
if len(industry_name) <1:
industry_name = 'null'
# 专业
profession_name = re.findall(r"最高学历/学位 专 业:(.*?)学 校:", page_text, re.S)[0]
if len(profession_name) <1:
profession_name = 'null'
# 学校
school_name = re.findall(r"学 校:(.*?)学历/学位", page_text, re.S)[0]
if len(school_name) <1:
school_name= 'null'
# 学历
education = re.findall(r"学历/学位:(.*?)个人信息户口/国籍", page_text, re.S)[0]
if len(education) <1:
education = 'null'
print(sex, age, dress, work_age, work_name, company_name, industry_name, profession_name, school_name,
education)
else:
continue
python爬取简历
最新推荐文章于 2023-02-20 11:00:17 发布