[python] boss直聘自動搜索簡歷聊天HR機器人


前言

該機器人完全仿照人是如何操作的,進行簡歷搜索和自動打招呼。


1、首先進行幾個關鍵位置的標定

1)簡歷的左上角
2)簡歷的”打招呼“按鈕
3)聊天對話框的輸入文字框的位置
4)關閉聊天對話框的按鈕的位置
5)”下一個“按鈕的位置

將上面5個位置定義爲P1~P5

標定相關的代碼:

pos1 = Point(0,0)
pos2 = Point(0,0)
pos3 = Point(0,0)
pos4 = Point(0,0)
pos5 = Point(0,0)
def get_key_pos():
    last_time = time.time()
    step = -1
    
    print("標定開始...")
    while 1<2:
        t = time.time() - last_time
        if  t > 5:
            last_time = time.time()
            if step == -1:
                print("請點擊一次簡歷左上角的空白處,並保持不動")
                step = 0
            elif step == 0:
                pos1.x,pos1.y = m.position()
                print("請點擊一次打招呼,並保持不動")
                step = 1
            elif step == 1:
                pos2.x,pos2.y = m.position()
                print("請點擊一次文字輸入框,並保持不動")
                step = 2
            elif step == 2:
                pos3.x,pos3.y = m.position()
                print("請點擊一次關閉對話框,並保持不動")
                step = 3
            elif step == 3:
                pos4.x,pos4.y = m.position()
                print("請點擊一次下一個(如果下一個右邊有下拉滾動條,則放在下一個的右側邊緣,否則放在左側邊緣),並保持不動")
                step = 4
            elif step == 4:
                pos5.x,pos5.y = m.position()
                print(pos1,pos2,pos3,pos4,pos5)
                return

2、拖拽鼠標複製簡歷的文字,並進行字符串匹配,對候選人進行人物畫像和打分

def people_filter():
    drag(Point(pos1.x,pos1.y),Point(pos1.x,1000),2,0)
    drag(Point(pos1.x,1000),Point(935,655),1)

    k.press_key(k.control_key)
    k.tap_key('c')
    time.sleep(1)
    k.release_key(k.control_key)

    m.move(1334, 461)      
    m.scroll(10)

    text = pyperclip.paste()
    ret = text.find("看過Ta的人還聯繫了")   #推薦信息給過濾掉
    if ret != -1:
        text = text[:ret]
        #print(text)

    #print("分析:",text)

    value = int(0)
    richness = text.count("\n") #根據多少行判斷是否豐富
    print(">>> 候選人,人物畫像: ")
    print("> 簡歷豐富度(多少行):",richness)
    if richness > 35:
        print("> 簡歷:豐富")
        value = value + 5
    else:
        print("> 簡歷:不豐富")     

    if text.find("本科") != -1:
        print("> 本科:YES")
    else: 
        print("> 本科:NO")

	#...省略很多關鍵詞匹配的代碼

    print("> 總分:", value)

    if value < 10:
        return 0
    else:
        return 1

這裏用了 PyMouse、PyKeyboard(用python操作鼠標和鍵盤)模塊,其中drag函數實現從Point1拖拽到Point2,最後一個參數爲0表示拖拽完畢不鬆手,爲1表示拖拽完畢鬆手。因此:

  • people_filter 函數的前兩行實現的功能是: 從簡歷的左上角向下拖拽到屏幕外(實現全選),然後再從屏幕外拖拽到簡歷的右下角
  • 接下來 4 行利用 PyKeyboard 發送 ctrl+c 的命令,進行復制
  • 接下來從剪切板中取出剛剛複製的內容 text = pyperclip.paste()
  • 最後進行關鍵詞匹配

3、篩選、聊天、下一個全流程狀態機

m = PyMouse()
k = PyKeyboard()

def hr_start():
    get_key_pos()

    last_time = time.time()
    step = -1
    while 1<2:
        t = time.time() - last_time
        if  t > 2:
            if step == -1:
                if people_filter() == 1:
                    step = 0
                else:
                    step = 4
            elif step == 0:
                m.click(pos2.x, pos2.y, 1)     
                step = 1
                print("溝通")
            elif step == 1:
                m.click(pos2.x, pos2.y, 1)      
                step = 2
                pyperclip.copy("您好~方便簡歷發過來嗎?")
                print("打開溝通對話框")
            elif step == 2:
                m.click(pos3.x, pos3.y , 1)     
                k.press_key(k.control_key)
                k.tap_key('v')
                time.sleep(1)
                k.release_key(k.control_key)
                k.tap_key(k.enter_key)
                step = 3
                print("輸入一句話")
            elif step == 3:
                m.click(pos4.x, pos4.y, 1)      #取整除 - 向下取接近除數的整數
                step = 4
                print("關閉溝通")
            elif step == 4:
                m.click(pos5.x, pos5.y, 1)
                time.sleep(1)
                step = -1
                print("下一個")

            #print("time=",t)
            last_time = time.time()

邏輯比較簡單:如果篩選的人滿足條件,則進行溝通,索要簡歷,如果不行繼續下一個


附錄

1.完整代碼 wget http://tuchuang.beautifulzzzz.com:3000/?path=/56/90620e0ab9098ef485037ad1eb5d31.png ,然後重命名爲.py,使用python3
2.[python] PyMouse、PyKeyboard用python操作鼠標和鍵盤


: 希望這個簡單的小 DEMO 能幫助你理解 python 的對鼠標鍵盤操作的模塊~
千萬不要用這種程序去做壞事~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章