Day 049

Udemy Python Bootcamp Day 049

Automating Job Applications on LikedIn

Setup Account And Resume

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

service = Service("/Users/****/Development/chromedriver")
driver = webdriver.Chrome(service=service)

LinkedIn에 올릴 마땅한 resume가 없어서 Zety에서 3천원주고 얼렁뚱땅만들어버렸다...

Automatically Login

from selenium.webdriver.common.keys import Keys

ACCOUNT_EMAIL = "*********@gmail.com"
ACCOUNT_PASSWORD = "*******"

sign_in_button = driver.find_element(By.CLASS_NAME, "nav__button-secondary")
sign_in_button.click()

time.sleep(1)

email = driver.find_element(By.ID, "username")
email.send_keys(ACCOUNT_EMAIL)
password = driver.find_element(By.ID, "password")
password.send_keys(ACCOUNT_PASSWORD)
password.send_keys(Keys.ENTER)

Apply for a Job

apply_button = driver.find_element(By.CLASS_NAME, "jobs-apply-button")
apply_button.click()

contact_number = driver.find_element(By.XPATH, '//*[@id="urn:li:fs_easyApplyFormElement:(urn:li:fs_normalized_jobPosting:2945846091,9,phoneNumber~nationalNumber)"]')
if contact_number.text == "":
    contact_number.send_keys(MY_NUMBER)
    
send_button = driver.find_element(By.CLASS_NAME, "artdeco-button")
send_button.click()

근데 send_button.click()이 뭔가 잘못됐는지 버튼이 안눌림...
그냥 확인만 해보자 하고 내가 수동으로 눌렀다가 지원이 되버림.....
아뇨 저기 제가 원래 그렇게 장난으로 입사지원하는 사람이 아닌데요,,,
설상가상으로 지원서가 조회됨..
연락은 어차피 안오겠지만 뭔가 죄송하네,,,, ㅋㅋㅋㅋㅋㅋㅋㅋ

save_button = driver.find_element(By.CLASS_NAME, "jobs-save-button")
save_button.click()

단순히 해당 기업 save하는 건 잘됩니다...

다음 스텝이 간편지원할때 note 요구하면 지원취소하는건데
또 지원되버릴까봐 못하겠음ㅎㅎ;;
그리고 안해봐도 어떻게 할지 대충 보임
왜냐면 내가 지원하는 거 만들때
send_button click하면 취소하겠냐고 물어봤거든....
그럼 send_button이 잘못됐다는건데 손대기가 무서움 암튼 무서움 ㅎ
오늘 플젝은 여기까지.....

FINAL

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import ElementClickInterceptedException

import time

ACCOUNT_EMAIL = "*******@gmail.com"
ACCOUNT_PASSWORD = "******"
MY_NUMBER = "*******"

service = Service("/Users/****/Development/chromedriver")
driver = webdriver.Chrome(service=service)

driver.get("https://www.linkedin.com/jobs/search/?f_LF=f_AL&geoId=103588929&keywords=python%20developer&location=%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD%20%EC%84%9C%EC%9A%B8")

sign_in_button = driver.find_element(By.CLASS_NAME, "nav__button-secondary")
sign_in_button.click()

time.sleep(1)

email = driver.find_element(By.ID, "username")
email.send_keys(ACCOUNT_EMAIL)
password = driver.find_element(By.ID, "password")
password.send_keys(ACCOUNT_PASSWORD)
password.send_keys(Keys.ENTER)

time.sleep(1)

all_listings = driver.find_elements(By.CSS_SELECTOR, ".job-card-container--clickable")

for listing in all_listings:
    print("called")
    listing.click()
    time.sleep(2)

    # Try to locate the apply button, if can't locate then skip the job.
    try:
        apply_button = driver.find_element(By.CSS_SELECTOR, ".jobs-s-apply button")
        apply_button.click()
        time.sleep(5)

        # If phone field is empty, then fill your phone number.
        phone = driver.find_element(By.CLASS_NAME, "fb-single-line-text__input")
        if phone.text == "":
            phone.send_keys(MY_NUMBER)

        submit_button = driver.find_element(By.CSS_SELECTOR, "footer button")

        # If the submit_button is a "Next" button, then this is a multi-step application, so skip.
        if submit_button.get_attribute("data-control-name") == "continue_unify":
            close_button = driver.find_element(By.CLASS_NAME, "artdeco-modal__dismiss")
            close_button.click()
            time.sleep(2)
            discard_button = driver.find_elements(By.CLASS_NAME, "artdeco-modal__confirm-dialog-btn")[1]
            discard_button.click()
            print("Complex application, skipped.")
            continue
        else:
            submit_button.click()

        # Once application completed, close the pop-up window.
        time.sleep(2)
        close_button = driver.find_element(By.CLASS_NAME, "artdeco-modal__dismiss")
        close_button.click()

    # If already applied to job or job is no longer accepting applications, then skip.
    except NoSuchElementException:
        print("No application button, skipped.")
        continue

time.sleep(5)
driver.quit()

암튼 final project는 이렇게 되는데 안젤라가 원하는 노트를 필요로하는 채용공고에 자동으로 접근하도록 만들수가 없어서..(만들수 없는거 맞아? 그냥 안만드는 거잖아..) final project 실행해보지는 않았음
그리고 또 파이참에서 NoSuchElementException를 인식 못하는데 이유를 모르겠네...?

+) 2022.03.26
import exception안해서 그런거였음..

좋은 웹페이지 즐겨찾기