Python提取PDF简历中的信息,写入Excel
↑ 关注 + 星标 ,每天学Python新技能
后台回复【大礼包】送你Python自学大礼包
今天为大家分享一个真实的案例。
目标资料背景:
是由求职者自行编制的简历材料,投递到人力资源部。由于其数据格式的不确定,对数据信息的采集带来了一定困难。我的解答思路是:
先从PDF文档中抓取文字信息保存到word文档中,然后再从word文档中读取文字信息保存到excel中。1. 将PDF文档中的文字读取到word中
import pdfplumber
from docx import Document
with pdfplumber.open('1_5的简历1632532336.pdf') as rpdf:
first_page = rpdf.pages[0]
print(first_page.extract_text())
doc = Document()
rpdfword = first_page.extract_text()
pages = doc.add_paragraph(rpdfword)
doc.save('测试2.docx')
2. 将word中读到的文字输入到excel中
#导入所需库
from docx import Document
import xlwings as xw
#写数据
def excel_write(a,path,sheetname,write_cols,write_rows):
app=xw.App(visible=False,add_book=False)
app.display_alerts=False
app.screen_updating=False
wb=app.books.open(path)
sht=wb.sheets[sheetname]
weizhi = []
try:
i = 0
while i!=len(write_cols):
j = 0
while j!=len(write_rows):
weizhi.append(write_cols[i]+str(write_rows[j]))
j+=1
i+=1
k=0
while k!=len(a):
sht.range(weizhi[k]).value=a[k].text
print(weizhi[k])
k+=1
finally:
wb.save()
wb.close()
app.kill()
if __name__ == "__main__":
#打开word文档
document = Document(u"测试2.docx")
#获取所有段落
all_paragraphs = document.paragraphs
print(len(all_paragraphs))
excel_path =r'报名人员信息统计表(模板).xls'
SheetName = r'Sheet1'
wcols = ['c','d','i','h','e','f','j','L']
#新读取一个简历要换一行
wrow = [3]
excel_write(all_paragraphs,excel_path,SheetName,wcols,wrow)
推荐阅读
评论