Repository navigation
Expand file tree
/
Copy pathEasyApply.py
More file actions
123 lines (92 loc) · 4.57 KB
/
Copy pathEasyApply.py
File metadata and controls
123 lines (92 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from LinkedinLinks import LinkedinLinks
import time
class EasyApply:
def __init__(self, data):
self.email = data["email"]
self.password = data["password"]
self.filters = data["filters"] or []
self.driver = self.__setup_driver()
def __setup_driver(self):
# Configure options for ChromeDriver
options = Options()
options.add_argument("--start-maximized") # Start browser maximized
options.add_argument("--disable-infobars")
options.add_argument("--disable-extensions")
# Initialize the ChromeDriver
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
return driver
def login(self):
# Open LinkedIn login page
self.driver.get(LinkedinLinks.get_url(LinkedinLinks.LOGIN))
# Enter username
username_input = self.driver.find_element(By.ID, "username")
username_input.send_keys(self.email) # Replace with your LinkedIn username
# Enter password
password_input = self.driver.find_element(By.ID, "password")
password_input.send_keys(self.password) # Replace with your LinkedIn password
# Submit the login form
password_input.send_keys(Keys.RETURN)
# Wait for login to finish
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "global-nav-search")))
def search_jobs(self, keyword_info: dict = {"title": "", "location": ""}):
self.driver.get(LinkedinLinks.get_url(LinkedinLinks.SEARCH_JOB))
# title of job input
title_input = self.driver.find_element(By.XPATH, "//input[starts-with(@id, 'jobs-search-box-keyword')]")
title_input.clear()
title_input.send_keys(keyword_info["title"])
# location of job input
location_input = self.driver.find_element(By.XPATH, "//input[starts-with(@id, 'jobs-search-box-location')]")
location_input.clear()
location_input.send_keys(keyword_info["location"])
# Submit the login form
title_input.send_keys(Keys.RETURN)
# Wait for job search to finish
WebDriverWait(self.driver, 20, 5).until(EC.presence_of_element_located((By.XPATH, "//button[text()='All filters']")))
def easy_apply_filter(self):
all_filters = self.driver.find_element(By.XPATH, "//button[text()='All filters']")
all_filters.click()
time.sleep(2) # TODO: To be replaced with WebDriverWait
easy_apply_button = self.driver.find_element(By.XPATH, "//h3[text()='Easy Apply']/following-sibling::div//input[@type='checkbox']")
time.sleep(1) # TODO: To be replaced with WebDriverWait
# Scroll into view if needed and click to toggle the switch
actions = ActionChains(self.driver)
actions.move_to_element(easy_apply_button).click().perform()
time.sleep(3) # TODO: To be replaced with WebDriverWait
def other_filters(self):
actions = ActionChains(self.driver)
for filter in self.filters:
# Remote filters
if filter == "On-site":
remote_filter = self.driver.find_element(By.ID, "advanced-filter-workplaceType-1")
actions.move_to_element(remote_filter).click().perform()
if filter == "Remote":
remote_filter = self.driver.find_element(By.ID, "advanced-filter-workplaceType-2")
actions.move_to_element(remote_filter).click().perform()
if filter == "Hybrid":
hybrid_filter = self.driver.find_element(By.ID, "advanced-filter-workplaceType-3")
actions.move_to_element(hybrid_filter)
time.sleep(2) # TODO: To be replaced with WebDriverWait
# apply filters
def apply_all_filters(self):
show_results_button = self.driver.find_element(By.XPATH, "//button[@data-test-reusables-filters-modal-show-results-button='true']")
show_results_button.click()
def find_offers(self):
total_number_of_offers = self.driver.find_element(By.CSS_SELECTOR, "div.jobs-search-results-list__subtitle").text.split(" ")[0].replace(",", "")
print(f"total number of offers found: {int(total_number_of_offers)}")
results_list = self.driver.find_elements(By.XPATH, "//li[contains(@class, 'jobs-search-results__list-item')]")
print(f"All jobs list in current page: {results_list}")
for result in results_list:
hover = ActionChains(self.driver).move_to_element(result)
hover.click().perform()
time.sleep(2)