欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長(zhǎng)資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          Python自動(dòng)化實(shí)踐之篩選簡(jiǎn)歷

          本篇文章給大家?guī)?lái)了關(guān)于python的相關(guān)知識(shí),其中主要介紹了關(guān)于簡(jiǎn)歷篩選的相關(guān)問題,包括了定義 ReadDoc 類用以讀取 word 文件以及定義 search_word 函數(shù)用以篩選的相關(guān)內(nèi)容,下面一起來(lái)看一下,希望對(duì)大家有幫助。

          Python自動(dòng)化實(shí)踐之篩選簡(jiǎn)歷

          推薦學(xué)習(xí):python視頻教程

          簡(jiǎn)歷篩選

          簡(jiǎn)歷相關(guān)信息如下:


          Python自動(dòng)化實(shí)踐之篩選簡(jiǎn)歷


          定義 ReadDoc 類用以讀取 word 文件

          已知條件:

          想要查找包含指定關(guān)鍵字的簡(jiǎn)歷(比如 Python、Java)


          實(shí)現(xiàn)思路:

          批量讀取每一個(gè) word 文件(通過 glob 獲取 word 信息),將他們的所有可讀內(nèi)容獲取,并通過關(guān)鍵字方式篩選,拿到目標(biāo)簡(jiǎn)歷地址。


          這里有個(gè)需要注意的地方就是,并不是所有的 "簡(jiǎn)歷" 都是以段落的形式呈現(xiàn)的,比如從 "獵聘" 網(wǎng)下載下來(lái)的簡(jiǎn)歷就是 "表格形式" 的,而 "boss" 上下載的簡(jiǎn)歷就是 "段落形式" 的,這里再進(jìn)行讀取的時(shí)候需要注意下,我們做的演示腳本練習(xí)就是 "表格形式" 的。


          這里的話,我們就可以專門定義一個(gè) "ReadDoc" 的類,里面定義兩個(gè)函數(shù),分別用于讀取 "段落" 和 "表格" 。

          實(shí)操案例腳本如下:

          # coding:utf-8from docx import Documentclass ReadDoc(object):              # 定義一個(gè) ReadDoc ,用以讀取 word 文件     def __init__(self, path):       # 構(gòu)造函數(shù)默認(rèn)傳入讀取 word 文件的路徑         self.doc = Document(path)         self.p_text = ''         self.table_text = ''          self.get_para()         self.get_table()       def get_para(self):             # 定義 get_para 函數(shù)用以讀取 word 文件的段落         for p in self.doc.paragraphs:             self.p_text += p.text + 'n'    # 讀取的段落內(nèi)容進(jìn)行換行         print(self.p_text)       def get_table(self):            # 定義 get_table 函數(shù)循環(huán)讀取表格內(nèi)容         for table in self.doc.tables:             for row in table.rows:                 _cell_str = ''      # 獲取每一行的完整信息                 for cell in row.cells:                     _cell_str += cell.text + ','    # 每一行加一個(gè) "," 隔開                 self.table_text += _cell_str + 'n'     # 讀取的表格內(nèi)容進(jìn)行換行         print(self.table_text)if __name__ == '__main__':     path = glob.os.path.join(glob.os.getcwd(), 'test_file/簡(jiǎn)歷1.docx')     doc = ReadDoc(path)     print(doc)

          看一下 ReadDoc 類的運(yùn)行結(jié)果


          Python自動(dòng)化實(shí)踐之篩選簡(jiǎn)歷


          定義 search_word 函數(shù)用以篩選 word 文件內(nèi)容符合想要的簡(jiǎn)歷

          OK,上文已經(jīng)成功讀取了簡(jiǎn)歷的 word 文檔,接下來(lái)我們要將讀取到的內(nèi)容通過帥選關(guān)鍵字信息的方式,過濾出包含有關(guān)鍵字的簡(jiǎn)歷。

          實(shí)操案例腳本如下:

          # coding:utf-8import globfrom docx import Documentclass ReadDoc(object):              # 定義一個(gè) ReadDoc ,用以讀取 word 文件     def __init__(self, path):       # 構(gòu)造函數(shù)默認(rèn)傳入讀取 word 文件的路徑         self.doc = Document(path)         self.p_text = ''         self.table_text = ''          self.get_para()         self.get_table()       def get_para(self):             # 定義 get_para 函數(shù)用以讀取 word 文件的段落         for p in self.doc.paragraphs:             self.p_text += p.text + 'n'    # 讀取的段落內(nèi)容進(jìn)行換行         # print(self.p_text)        # 調(diào)試打印輸出 word 文件的段落內(nèi)容       def get_table(self):            # 定義 get_table 函數(shù)循環(huán)讀取表格內(nèi)容         for table in self.doc.tables:             for row in table.rows:                 _cell_str = ''      # 獲取每一行的完整信息                 for cell in row.cells:                     _cell_str += cell.text + ','    # 每一行加一個(gè) "," 隔開                 self.table_text += _cell_str + 'n'     # 讀取的表格內(nèi)容進(jìn)行換行         # print(self.table_text)    # 調(diào)試打印輸出 word 文件的表格內(nèi)容def search_word(path, targets):     # 定義 search_word 用以篩選符合內(nèi)容的簡(jiǎn)歷;傳入 path 與 targets(targets 為列表)     result = glob.glob(path)     final_result = []               # 定義一個(gè)空列表,用以后續(xù)存儲(chǔ)文件的信息      for i in result:             # for 循環(huán)獲取 result 內(nèi)容          isuse = True                # 是否可用          if glob.os.path.isfile(i):       # 判斷是否是文件             if i.endswith('.docx'):      # 判斷文件后綴是否是 "docx" ,若是,則利用 ReadDoc類 實(shí)例化該文件對(duì)象                 doc = ReadDoc(i)                 p_text = doc.p_text         # 獲取 word 文件內(nèi)容                 table_text = doc.table_text                 all_text = p_text + table_text                for target in targets:      # for 循環(huán)判斷關(guān)鍵字信息內(nèi)容是否存在                     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', '埋點(diǎn)'])      # 埋點(diǎn)是為了演示效果,故意在 "簡(jiǎn)歷1.docx" 加上的     print(result)

          運(yùn)行結(jié)果如下:


          Python自動(dòng)化實(shí)踐之篩選簡(jiǎn)歷


          推薦學(xué)習(xí):python視頻教程

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)