-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
139 lines (103 loc) · 4.37 KB
/
main.py
File metadata and controls
139 lines (103 loc) · 4.37 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
124
125
126
127
128
129
130
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from time import sleep, time
from selenium.webdriver.common.keys import Keys
import os
from dotenv import load_dotenv
from selenium.webdriver.common.utils import keys_to_typing
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
load_dotenv()
# login info
USERNAME = os.getenv("LINKEDIN_USERNAME")
PASSWORD = os.getenv("PASSWORD")
PHONE_NUMBER = os.getenv("PHONE_NUMBER")
# Setup Chrome driver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.linkedin.com/feed/")
# wait for loading
sleep(3)
# Login pop-ups
try:
fill_email = driver.find_element(By.XPATH, value='//*[@id="username"]')
fill_email.send_keys(USERNAME)
fill_password = driver.find_element(By.XPATH, value='//*[@id="password"]')
fill_password.send_keys(PASSWORD)
click_login = driver.find_element(By.XPATH, value='//*[@id="organic-div"]/form/div[4]/button')
click_login.click()
except NoSuchElementException:
print("No element found")
# Potential Captcha so you get about 20 seconds bc some of them are CRAZY
sleep(20)
# Search for a job
try:
click_search = driver.find_element(By.XPATH, value='//*[@id="global-nav-search"]/div/button')
click_search.click()
search_box = driver.find_element(By.XPATH, value='//*[@id="global-nav-typeahead"]/input')
search_box.send_keys("roethlisberger door to door sales")
search_box.send_keys(Keys.ENTER)
except NoSuchElementException:
print("No search element found")
# CLick first job
try:
sleep(3)
click_jobs = driver.find_element(By.XPATH, value='//*[@id="search-reusables__filters-bar"]/ul/li[1]/button')
click_jobs.click()
sleep(3)
click_easy_apply = driver.find_element(By.XPATH, value='//*[@id="jobs-apply-button-id"]/span')
click_easy_apply.click()
sleep(2)
phone_number = driver.find_element(By.XPATH, value='//*[contains(@id, "phoneNumber-nationalNumber")]')
phone_number.click()
phone_number.send_keys(PHONE_NUMBER)
next1 = driver.find_element(By.XPATH, value='//button[.//span[text()="Next"]]')
next1.click()
# Next page
next2 = driver.find_element(By.XPATH, value='//button[.//span[text()="Next"]]')
next2.click()
# Page w/ radios, Find all "Yes" labels instead of radio buttons
wait = WebDriverWait(driver, 10)
yes_labels = wait.until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'label[data-test-text-selectable-option__label="Yes"]')))
# Click each label
for label in yes_labels:
try:
WebDriverWait(driver, 5).until(EC.element_to_be_clickable(label))
label.click()
except Exception as e:
print(f"Could not click label: {e}")
# Dropdown
try:
# Find the select element
select_element = driver.find_element(By.CSS_SELECTOR, 'select[id*="multipleChoice"]')
# Create Select object
dropdown = Select(select_element)
# Select by visible text
dropdown.select_by_visible_text("Yes")
# Or select by value if you know it
# dropdown.select_by_value("Yes")
except NoSuchElementException:
print("Review the dropdown stuff")
# Years of experience, I chose a random number: 3
years_exp = driver.find_element(By.CSS_SELECTOR, value='input.artdeco-text-input--input[type="text"]')
years_exp.click()
years_exp.send_keys("3")
next3 = driver.find_element(By.XPATH, value='//button[.//span[text()="Next"]]')
next3.click()
# US Work auth page
sleep(3)
work_auth = driver.find_element(By.CSS_SELECTOR, 'label[data-test-text-selectable-option__label="Yes"]')
work_auth.click()
review = driver.find_element(By.CSS_SELECTOR, value='button.artdeco-button.artdeco-button--2.artdeco-button--primary')
review.click()
# Submit page (must use scroll function)
sleep(2)
submit_button = driver.find_element(By.CSS_SELECTOR, value='button[aria-label="Submit application"]')
driver.execute_script("arguments[0].scrollIntoView(true);", submit_button)
submit_button.click()
except NoSuchElementException:
print("Didn't work")