python批量提取word指定内容_python 批量提取word应聘登记表数据+情感分析

1.本代码做情感分析,需要先注册百度AI开发者账号,获取

APP_ID = '你的百度id '

API_KEY = '你的百度开发api'

SECRET_KEY = '你的百度开发密钥'

2.对于不同格式的应聘登记表,需要具体定位数据位置

比如:name = tables[j].cell(0, 1).text 表示第j个表格第一行第二个数据

在header变量中可修改自己需要的字段

注意:全局变量不要重名,最后添加到row列表里即可。

from docx import Document

import pandas as pd

import os

import datetime

from openpyxl import Workbook

from aip import AipNlp

def sentiment_analysis(msg):

APP_ID = '你的百度id '

API_KEY = '你的百度开发api'

SECRET_KEY = '你的百度开发密钥'

client = AipNlp(APP_ID, API_KEY, SECRET_KEY)

r=client.sentimentClassify(msg)

now_mod_rank =r['items'][0]['positive_prob']

return now_mod_rank

for fpath, dirs, fs in os.walk(r'E:\data\应聘登记表202007'):

# name_list=[]

wb = Workbook()

sheet = wb.active

header = ['序号','姓名', '英文名', '出生年月', '籍贯', '民族', '身份证','联系电话','微信号','邮箱地址','现居住地址','最快入职时间','最近一份工作合同截至日期',

'工作/实习起止年月','工作/实习单位名称','部门/职位','最后薪水','离职原因','证明人及联系方式','工作/实习起止年月2','工作/实习单位名称2','部门/职位2','最后薪水2','离职原因2','证明人及联系方式2',

'学历一','毕业院校及专业一','起止时间一','学历二','毕业院校及专业二','起止时间二','家庭关系','家庭成员','年龄','工作单位','职务职称','家庭成员联系电话','附加信息',"情感",'情感2']

sheet.append(header)

n = 0

for dir in fs:

print(dir)

path = os.path.join(fpath, dir)

doc = Document(path)

table_index=0

tables = doc.tables

table_index=0

for j in range(len(tables)):

table_index +=1

if table_index ==1:

try:

# 姓名

global name,English_name, birth_date, ji_guan, min_zu,身份证,phone,wei_xin,you_xianag,address,ru_zhi,he_tong_date

name = tables[j].cell(0, 1).text

# name_list.append(name)

#英文名

English_name = tables[j].cell(0, 4).text

#出生日期

birth_date = tables[j].cell(0, 7).text

# if '-' in birth_date:

# birth_date = datetime.datetime.strptime(birth_date, '%d/%m').strftime('2020/%m/%d')

# else:

# birth_date = '/'

# 籍贯

ji_guan = tables[j].cell(0, 11).text

#民族

min_zu = tables[j].cell(0, 13).text

#身份证

身份证 = tables[j].cell(1, 2).text.strip()

# 联系电话

phone = tables[j].cell(1, 9).text.strip()

# 微信号

wei_xin = tables[j].cell(2, 2).text.strip()

# 邮箱地址

you_xianag = tables[j].cell(2, 9).text.strip()

# 现居住地址

address = tables[j].cell(3, 2).text.strip()

# 最快入职时间

ru_zhi = tables[j].cell(4, 2).text.strip()

# 最近一份工作合同截至日期

he_tong_date = tables[j].cell(4, 11).text.strip()

except Exception as error:

# 捕获异常,也可以用log写到日志里方便查看和管理

print(error)

continue

if table_index ==2:

try:

global work_date, work_name, zhi_wei, last_salary,lizhi_reason,zheng_ming,work_date1,work_name1,zhi_wei1,last_salary1,lizhi_reason1,zheng_ming1,qing_gan,qing_gan2

# 工作/实习起止年月

work_date = tables[j].cell(1, 0).text

work_date1 =tables[j].cell(2, 0).text

#工作/实习单位名称

work_name = tables[j].cell(1, 1).text

work_name1 =tables[j].cell(2, 1).text

#部门/职位

zhi_wei = tables[j].cell(1, 2).text

zhi_wei1 = tables[j].cell(2, 2).text

# if '/' in birth_date:

# birth_date = datetime.datetime.strptime(birth_date, '%d/%m').strftime('2020-%m-%d')

# else:

# birth_date = '-'

# 最后薪水

last_salary = tables[j].cell(1, 3).text

last_salary1 = tables[j].cell(2, 3).text

#离职原因

lizhi_reason = tables[j].cell(1, 4).text

lizhi_reason1 =tables[j].cell(2, 4).text

#证明人及联系方式

zheng_ming = tables[j].cell(1,5).text.strip()

zheng_ming1 =tables[j].cell(2, 5).text.strip()

# n += 1

qing_gan = sentiment_analysis(lizhi_reason)

qing_gan2 = sentiment_analysis(lizhi_reason1)

print(n, work_date, work_name, zhi_wei, last_salary,lizhi_reason,zheng_ming )

except Exception as error:

# 捕获异常,也可以用log写到日志里方便查看和管理

print(error)

continue

if table_index ==3:

# for i in range(0,10):

# print( tables[j].cell(1, i).text,i)

global xue_li1, biye_cumpus1, cumpus_time1, xue_li2,biye_cumpus2,cumpus_time2

try:

# 学历一

xue_li1 = tables[j].cell(0, 1).text

#毕业院校及专业一

biye_cumpus1 = tables[j].cell(0, 3).text

#起止时间一

cumpus_time1 = tables[j].cell(0, 7).text

# if '/' in birth_date:

# birth_date = datetime.datetime.strptime(birth_date, '%d/%m').strftime('2020-%m-%d')

# else:

# birth_date = '-'

# 学历二

xue_li2 = tables[j].cell(1, 1).text

biye_cumpus2 = tables[j].cell(1, 3).text

#起止时间二

cumpus_time2 = tables[j].cell(1,7).text.strip()

except Exception as error:

# 捕获异常,也可以用log写到日志里方便查看和管理

print(error)

continue

if table_index ==4:

# for i in range(0,10):

# print( tables[j].cell(1, i).text,i)

global family, familys, age, work_address,zhi_cheng,family_phone

try:

# 家庭关系

family = tables[j].cell(1, 0).text +'/'+ tables[j].cell(2, 0).text+'/'+ tables[j].cell(3, 0).text +'/'+ tables[j].cell(4, 0).text

#家庭成员

familys = tables[j].cell(1, 1).text +'/'+ tables[j].cell(2, 1).text +'/'+ tables[j].cell(3, 1).text +'/'+ tables[j].cell(4, 1).text

#年龄

age = tables[j].cell(1, 2).text +'/'+ tables[j].cell(2, 2).text +'/'+ tables[j].cell(3, 2).text +'/'+ tables[j].cell(4, 2).text

# if '/' in birth_date:

# birth_date = datetime.datetime.strptime(birth_date, '%d/%m').strftime('2020-%m-%d')

# else:

# birth_date = '-'

# 工作单位

work_address = tables[j].cell(1, 3).text +'/'+ tables[j].cell(2, 3).text +'/'+ tables[j].cell(3, 3).text +'/'+ tables[j].cell(4, 3).text

#职务职称

zhi_cheng = tables[j].cell(1, 4).text +'/'+ tables[j].cell(2, 4).text +'/'+ tables[j].cell(3, 4).text +'/'+ tables[j].cell(4, 4).text

#家庭成员联系电话

family_phone = tables[j].cell(1,5).text.strip() +'/'+ tables[j].cell(2, 5).text +'/'+ tables[j].cell(3, 5).text +'/'+ tables[j].cell(4, 5).text

except Exception as error:

# 捕获异常,也可以用log写到日志里方便查看和管理

print(error)

continue

if table_index ==5:

try:

# 家庭关系

fujia = tables[j].cell(0, 0).text

#家庭成员

n+=1

# print(fujia)

row = [n, name, English_name, birth_date, ji_guan, min_zu,身份证,phone,wei_xin,you_xianag,address,ru_zhi,he_tong_date,work_date, work_name, zhi_wei, last_salary,lizhi_reason,zheng_ming,

work_date1,work_name1,zhi_wei1,last_salary1,lizhi_reason1,zheng_ming1,xue_li1, biye_cumpus1, cumpus_time1, xue_li2,biye_cumpus2,cumpus_time2,family, familys, age, work_address,zhi_cheng,family_phone,fujia,qing_gan,qing_gan2]

# list_line.append(row)

sheet.append(row)

except Exception as error:

# 捕获异常,也可以用log写到日志里方便查看和管理

print(error)

continue

# sheet.append(name_list)

wb.save(r'E:\data\应聘登记表\别名.xlsx')

可视化结果:

066b6c623439

image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值