이 기사에서는 단어 파일을 읽는 ReadDoc 클래스를 정의하고 필터링하는 search_word 함수를 정의하는 등 이력서 심사와 관련된 문제를 주로 소개하는 python에 대한 관련 지식을 제공하므로 함께 살펴보시기 바랍니다. 모두에게 도움이 되십시오. Y 추천 학습: tPython 동영상 튜토리얼
이력서 심사
조건을 알고 있음:
지정된 키워드(예: Python, Java)가 포함된 이력서를 찾으려면
구현 아이디어:
각 단어 파일을 일괄적으로 읽고(glob을 통해 단어 정보 얻기) 읽을 수 있는 모든 콘텐츠를 얻은 다음 키워드를 전달합니다. 대상 이력서 주소를 가져오는 방법입니다.
这里有个需要注意的地方就是,并不是所有的 "简历" 都是以段落的形式呈现的,比如从 "猎聘" 网下载下来的简历就是 "表格形式" 的,而 "boss" 上下载的简历就是 "段落形式" 的,这里再进行读取的时候需要注意下,我们做的演示脚本练习就是 "表格形式" 的。
这里的话,我们就可以专门定义一个 "ReadDoc" 的类,里面定义两个函数,分别用于读取 "段落" 和 "表格" 。
实操案例脚本如下:
# coding:utf-8from docx import Documentclass ReadDoc(object): # 定义一个 ReadDoc ,用以读取 word 文件 def __init__(self, path): # 构造函数默认传入读取 word 文件的路径 self.doc = Document(path) self.p_text = '' self.table_text = '' self.get_para() self.get_table() def get_para(self): # 定义 get_para 函数用以读取 word 文件的段落 for p in self.doc.paragraphs: self.p_text += p.text + '\n' # 读取的段落内容进行换行 print(self.p_text) def get_table(self): # 定义 get_table 函数循环读取表格内容 for table in self.doc.tables: for row in table.rows: _cell_str = '' # 获取每一行的完整信息 for cell in row.cells: _cell_str += cell.text + ',' # 每一行加一个 "," 隔开 self.table_text += _cell_str + '\n' # 读取的表格内容进行换行 print(self.table_text)if __name__ == '__main__': path = glob.os.path.join(glob.os.getcwd(), 'test_file/简历1.docx') doc = ReadDoc(path) print(doc)
看一下 ReadDoc
여기서 한 가지 주목할 점은 모든 "이력서"가 문단 형식으로 표시되는 것은 아니라는 점입니다. 예를 들어 "Liepin" 웹사이트에서 다운로드한 이력서는 "표 형식"으로 되어 있고, 에서 다운로드한 이력서는 "표 형식"입니다. "boss"는 "단락 형식"입니다. 여기서 읽을 때 주의할 점은 우리가 수행한 데모 스크립트 연습이 "표 형식"입니다.
여기서 "단락"과 "표"를 읽는 두 가지 함수를 정의하는 "ReadDoc" 클래스를 구체적으로 정의할 수 있습니다.
# coding:utf-8import globfrom docx import Documentclass ReadDoc(object): # 定义一个 ReadDoc ,用以读取 word 文件 def __init__(self, path): # 构造函数默认传入读取 word 文件的路径 self.doc = Document(path) self.p_text = '' self.table_text = '' self.get_para() self.get_table() def get_para(self): # 定义 get_para 函数用以读取 word 文件的段落 for p in self.doc.paragraphs: self.p_text += p.text + '\n' # 读取的段落内容进行换行 # print(self.p_text) # 调试打印输出 word 文件的段落内容 def get_table(self): # 定义 get_table 函数循环读取表格内容 for table in self.doc.tables: for row in table.rows: _cell_str = '' # 获取每一行的完整信息 for cell in row.cells: _cell_str += cell.text + ',' # 每一行加一个 "," 隔开 self.table_text += _cell_str + '\n' # 读取的表格内容进行换行 # print(self.table_text) # 调试打印输出 word 文件的表格内容def search_word(path, targets): # 定义 search_word 用以筛选符合内容的简历;传入 path 与 targets(targets 为列表) result = glob.glob(path) final_result = [] # 定义一个空列表,用以后续存储文件的信息 for i in result: # for 循环获取 result 内容 isuse = True # 是否可用 if glob.os.path.isfile(i): # 判断是否是文件 if i.endswith('.docx'): # 判断文件后缀是否是 "docx" ,若是,则利用 ReadDoc类 实例化该文件对象 doc = ReadDoc(i) p_text = doc.p_text # 获取 word 文件内容 table_text = doc.table_text all_text = p_text + table_text for target in targets: # for 循环判断关键字信息内容是否存在 if target not in all_text: isuse = False break if not isuse: continue final_result.append(i) return final_resultif __name__ == '__main__': path = glob.os.path.join(glob.os.getcwd(), '*') result = search_word(path, ['python', 'golang', 'react', '埋点']) # 埋点是为了演示效果,故意在 "简历1.docx" 加上的 print(result)
ReadDoc
클래스의 실행 결과를 살펴보세요
필터링할 search_word 함수 정의 원하는 이력서와 일치하는 단어 파일 내용
실제 사례 스크립트는 다음과 같습니다. rrreee실행 결과는 다음과 같습니다.
🎜🎜🎜🎜🎜🎜추천 학습: 🎜python 비디오 튜토리얼🎜🎜위 내용은 이력서 심사를 위한 Python 자동화 실습의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!