-
Notifications
You must be signed in to change notification settings - Fork 345
/
Copy patheasyapplybot.py
726 lines (616 loc) · 30.3 KB
/
easyapplybot.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
from __future__ import annotations
import json
import csv
import logging
import os
import random
import re
import time
from datetime import datetime, timedelta
import getpass
from pathlib import Path
import pandas as pd
import pyautogui
import yaml
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service as ChromeService
import webdriver_manager.chrome as ChromeDriverManager
ChromeDriverManager = ChromeDriverManager.ChromeDriverManager
log = logging.getLogger(__name__)
def setupLogger() -> None:
dt: str = datetime.strftime(datetime.now(), "%m_%d_%y %H_%M_%S ")
if not os.path.isdir('./logs'):
os.mkdir('./logs')
# TODO need to check if there is a log dir available or not
logging.basicConfig(filename=('./logs/' + str(dt) + 'applyJobs.log'), filemode='w',
format='%(asctime)s::%(name)s::%(levelname)s::%(message)s', datefmt='./logs/%d-%b-%y %H:%M:%S')
log.setLevel(logging.DEBUG)
c_handler = logging.StreamHandler()
c_handler.setLevel(logging.DEBUG)
c_format = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s', '%H:%M:%S')
c_handler.setFormatter(c_format)
log.addHandler(c_handler)
class EasyApplyBot:
setupLogger()
# MAX_SEARCH_TIME is 10 hours by default, feel free to modify it
MAX_SEARCH_TIME = 60 * 60
def __init__(self,
username,
password,
phone_number,
# profile_path,
salary,
rate,
uploads={},
filename='output.csv',
blacklist=[],
blackListTitles=[],
experience_level=[]
) -> None:
log.info("Welcome to Easy Apply Bot")
dirpath: str = os.getcwd()
log.info("current directory is : " + dirpath)
log.info("Please wait while we prepare the bot for you")
if experience_level:
experience_levels = {
1: "Entry level",
2: "Associate",
3: "Mid-Senior level",
4: "Director",
5: "Executive",
6: "Internship"
}
applied_levels = [experience_levels[level] for level in experience_level]
log.info("Applying for experience level roles: " + ", ".join(applied_levels))
else:
log.info("Applying for all experience levels")
self.uploads = uploads
self.salary = salary
self.rate = rate
# self.profile_path = profile_path
past_ids: list | None = self.get_appliedIDs(filename)
self.appliedJobIDs: list = past_ids if past_ids != None else []
self.filename: str = filename
self.options = self.browser_options()
self.browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=self.options)
self.wait = WebDriverWait(self.browser, 30)
self.blacklist = blacklist
self.blackListTitles = blackListTitles
self.start_linkedin(username, password)
self.phone_number = phone_number
self.experience_level = experience_level
self.locator = {
"next": (By.CSS_SELECTOR, "button[aria-label='Continue to next step']"),
"review": (By.CSS_SELECTOR, "button[aria-label='Review your application']"),
"submit": (By.CSS_SELECTOR, "button[aria-label='Submit application']"),
"error": (By.CLASS_NAME, "artdeco-inline-feedback__message"),
"upload_resume": (By.XPATH, "//*[contains(@id, 'jobs-document-upload-file-input-upload-resume')]"),
"upload_cv": (By.XPATH, "//*[contains(@id, 'jobs-document-upload-file-input-upload-cover-letter')]"),
"follow": (By.CSS_SELECTOR, "label[for='follow-company-checkbox']"),
"upload": (By.NAME, "file"),
"search": (By.CLASS_NAME, "jobs-search-results-list"),
"links": ("xpath", '//div[@data-job-id]'),
"fields": (By.CLASS_NAME, "jobs-easy-apply-form-section__grouping"),
"radio_select": (By.CSS_SELECTOR, "input[type='radio']"), #need to append [value={}].format(answer)
"multi_select": (By.XPATH, "//*[contains(@id, 'text-entity-list-form-component')]"),
"text_select": (By.CLASS_NAME, "artdeco-text-input--input"),
"2fa_oneClick": (By.ID, 'reset-password-submit-button'),
"easy_apply_button": (By.XPATH, '//button[contains(@class, "jobs-apply-button")]')
}
#initialize questions and answers file
self.qa_file = Path("qa.csv")
self.answers = {}
#if qa file does not exist, create it
if self.qa_file.is_file():
df = pd.read_csv(self.qa_file)
for index, row in df.iterrows():
self.answers[row['Question']] = row['Answer']
#if qa file does exist, load it
else:
df = pd.DataFrame(columns=["Question", "Answer"])
df.to_csv(self.qa_file, index=False, encoding='utf-8')
def get_appliedIDs(self, filename) -> list | None:
try:
df = pd.read_csv(filename,
header=None,
names=['timestamp', 'jobID', 'job', 'company', 'attempted', 'result'],
lineterminator='\n',
encoding='utf-8')
df['timestamp'] = pd.to_datetime(df['timestamp'], format="%Y-%m-%d %H:%M:%S")
df = df[df['timestamp'] > (datetime.now() - timedelta(days=2))]
jobIDs: list = list(df.jobID)
log.info(f"{len(jobIDs)} jobIDs found")
return jobIDs
except Exception as e:
log.info(str(e) + " jobIDs could not be loaded from CSV {}".format(filename))
return None
def browser_options(self):
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument("--ignore-certificate-errors")
options.add_argument('--no-sandbox')
options.add_argument("--disable-extensions")
#options.add_argument(r'--remote-debugging-port=9222')
#options.add_argument(r'--profile-directory=Person 1')
# Disable webdriver flags or you will be easily detectable
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
# Load user profile
#options.add_argument(r"--user-data-dir={}".format(self.profile_path))
return options
def start_linkedin(self, username, password) -> None:
log.info("Logging in.....Please wait :) ")
self.browser.get("https://www.linkedin.com/login?trk=guest_homepage-basic_nav-header-signin")
try:
user_field = self.browser.find_element("id","username")
pw_field = self.browser.find_element("id","password")
login_button = self.browser.find_element("xpath",
'//*[@id="organic-div"]/form/div[3]/button')
user_field.send_keys(username)
user_field.send_keys(Keys.TAB)
time.sleep(2)
pw_field.send_keys(password)
time.sleep(2)
login_button.click()
time.sleep(15)
# if self.is_present(self.locator["2fa_oneClick"]):
# oneclick_auth = self.browser.find_element(by='id', value='reset-password-submit-button')
# if oneclick_auth is not None:
# log.info("additional authentication required, sleep for 15 seconds so you can do that")
# time.sleep(15)
# else:
# time.sleep()
except TimeoutException:
log.info("TimeoutException! Username/password field or login button not found")
def fill_data(self) -> None:
self.browser.set_window_size(1, 1)
self.browser.set_window_position(2000, 2000)
def start_apply(self, positions, locations) -> None:
start: float = time.time()
self.fill_data()
self.positions = positions
self.locations = locations
combos: list = []
while len(combos) < len(positions) * len(locations):
position = positions[random.randint(0, len(positions) - 1)]
location = locations[random.randint(0, len(locations) - 1)]
combo: tuple = (position, location)
if combo not in combos:
combos.append(combo)
log.info(f"Applying to {position}: {location}")
location = "&location=" + location
self.applications_loop(position, location)
if len(combos) > 500:
break
# self.finish_apply() --> this does seem to cause more harm than good, since it closes the browser which we usually don't want, other conditions will stop the loop and just break out
def applications_loop(self, position, location):
count_application = 0
count_job = 0
jobs_per_page = 0
start_time: float = time.time()
log.info("Looking for jobs.. Please wait..")
self.browser.set_window_position(1, 1)
self.browser.maximize_window()
self.browser, _ = self.next_jobs_page(position, location, jobs_per_page, experience_level=self.experience_level)
log.info("Looking for jobs.. Please wait..")
while time.time() - start_time < self.MAX_SEARCH_TIME:
try:
log.info(f"{(self.MAX_SEARCH_TIME - (time.time() - start_time)) // 60} minutes left in this search")
# sleep to make sure everything loads, add random to make us look human.
randoTime: float = random.uniform(1.5, 2.9)
log.debug(f"Sleeping for {round(randoTime, 1)}")
#time.sleep(randoTime)
self.load_page(sleep=0.5)
# LinkedIn displays the search results in a scrollable <div> on the left side, we have to scroll to its bottom
# scroll to bottom
if self.is_present(self.locator["search"]):
scrollresults = self.get_elements("search")
# self.browser.find_element(By.CLASS_NAME,
# "jobs-search-results-list"
# )
# Selenium only detects visible elements; if we scroll to the bottom too fast, only 8-9 results will be loaded into IDs list
for i in range(300, 3000, 100):
self.browser.execute_script("arguments[0].scrollTo(0, {})".format(i), scrollresults[0])
scrollresults = self.get_elements("search")
#time.sleep(1)
# get job links, (the following are actually the job card objects)
if self.is_present(self.locator["links"]):
links = self.get_elements("links")
# links = self.browser.find_elements("xpath",
# '//div[@data-job-id]'
# )
jobIDs = {} #{Job id: processed_status}
# children selector is the container of the job cards on the left
for link in links:
if 'Applied' not in link.text: #checking if applied already
if link.text not in self.blacklist: #checking if blacklisted
jobID = link.get_attribute("data-job-id")
if jobID == "search":
log.debug("Job ID not found, search keyword found instead? {}".format(link.text))
continue
else:
jobIDs[jobID] = "To be processed"
if len(jobIDs) > 0:
self.apply_loop(jobIDs)
self.browser, jobs_per_page = self.next_jobs_page(position,
location,
jobs_per_page,
experience_level=self.experience_level)
else:
self.browser, jobs_per_page = self.next_jobs_page(position,
location,
jobs_per_page,
experience_level=self.experience_level)
except Exception as e:
print(e)
def apply_loop(self, jobIDs):
for jobID in jobIDs:
if jobIDs[jobID] == "To be processed":
applied = self.apply_to_job(jobID)
if applied:
log.info(f"Applied to {jobID}")
else:
log.info(f"Failed to apply to {jobID}")
jobIDs[jobID] == applied
def apply_to_job(self, jobID):
# #self.avoid_lock() # annoying
# get job page
self.get_job_page(jobID)
# let page load
time.sleep(1)
# get easy apply button
button = self.get_easy_apply_button()
# word filter to skip positions not wanted
if button is not False:
if any(word in self.browser.title for word in blackListTitles):
log.info('skipping this application, a blacklisted keyword was found in the job position')
string_easy = "* Contains blacklisted keyword"
result = False
else:
string_easy = "* has Easy Apply Button"
log.info("Clicking the EASY apply button")
button.click()
clicked = True
time.sleep(1)
self.fill_out_fields()
result: bool = self.send_resume()
if result:
string_easy = "*Applied: Sent Resume"
else:
string_easy = "*Did not apply: Failed to send Resume"
elif "You applied on" in self.browser.page_source:
log.info("You have already applied to this position.")
string_easy = "* Already Applied"
result = False
else:
log.info("The Easy apply button does not exist.")
string_easy = "* Doesn't have Easy Apply Button"
result = False
# position_number: str = str(count_job + jobs_per_page)
log.info(f"\nPosition {jobID}:\n {self.browser.title} \n {string_easy} \n")
self.write_to_file(button, jobID, self.browser.title, result)
return result
def write_to_file(self, button, jobID, browserTitle, result) -> None:
def re_extract(text, pattern):
target = re.search(pattern, text)
if target:
target = target.group(1)
return target
timestamp: str = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
attempted: bool = False if button == False else True
job = re_extract(browserTitle.split(' | ')[0], r"\(?\d?\)?\s?(\w.*)")
company = re_extract(browserTitle.split(' | ')[1], r"(\w.*)")
toWrite: list = [timestamp, jobID, job, company, attempted, result]
with open(self.filename, 'a+') as f:
writer = csv.writer(f)
writer.writerow(toWrite)
def get_job_page(self, jobID):
job: str = 'https://www.linkedin.com/jobs/view/' + str(jobID)
self.browser.get(job)
self.job_page = self.load_page(sleep=0.5)
return self.job_page
def get_easy_apply_button(self):
EasyApplyButton = False
try:
buttons = self.get_elements("easy_apply_button")
# buttons = self.browser.find_elements("xpath",
# '//button[contains(@class, "jobs-apply-button")]'
# )
for button in buttons:
if "Easy Apply" in button.text:
EasyApplyButton = button
self.wait.until(EC.element_to_be_clickable(EasyApplyButton))
else:
log.debug("Easy Apply button not found")
except Exception as e:
print("Exception:",e)
log.debug("Easy Apply button not found")
return EasyApplyButton
def fill_out_fields(self):
fields = self.browser.find_elements(By.CLASS_NAME, "jobs-easy-apply-form-section__grouping")
for field in fields:
if "Mobile phone number" in field.text:
field_input = field.find_element(By.TAG_NAME, "input")
field_input.clear()
field_input.send_keys(self.phone_number)
return
def get_elements(self, type) -> list:
elements = []
element = self.locator[type]
if self.is_present(element):
elements = self.browser.find_elements(element[0], element[1])
return elements
def is_present(self, locator):
return len(self.browser.find_elements(locator[0],
locator[1])) > 0
def send_resume(self) -> bool:
def is_present(button_locator) -> bool:
return len(self.browser.find_elements(button_locator[0],
button_locator[1])) > 0
try:
#time.sleep(random.uniform(1.5, 2.5))
next_locator = (By.CSS_SELECTOR,
"button[aria-label='Continue to next step']")
review_locator = (By.CSS_SELECTOR,
"button[aria-label='Review your application']")
submit_locator = (By.CSS_SELECTOR,
"button[aria-label='Submit application']")
error_locator = (By.CLASS_NAME,"artdeco-inline-feedback__message")
upload_resume_locator = (By.XPATH, '//span[text()="Upload resume"]')
upload_cv_locator = (By.XPATH, '//span[text()="Upload cover letter"]')
# WebElement upload_locator = self.browser.find_element(By.NAME, "file")
follow_locator = (By.CSS_SELECTOR, "label[for='follow-company-checkbox']")
submitted = False
loop = 0
while loop < 2:
time.sleep(1)
# Upload resume
if is_present(upload_resume_locator):
#upload_locator = self.browser.find_element(By.NAME, "file")
try:
resume_locator = self.browser.find_element(By.XPATH, "//*[contains(@id, 'jobs-document-upload-file-input-upload-resume')]")
resume = self.uploads["Resume"]
resume_locator.send_keys(resume)
except Exception as e:
log.error(e)
log.error("Resume upload failed")
log.debug("Resume: " + resume)
log.debug("Resume Locator: " + str(resume_locator))
# Upload cover letter if possible
if is_present(upload_cv_locator):
cv = self.uploads["Cover Letter"]
cv_locator = self.browser.find_element(By.XPATH, "//*[contains(@id, 'jobs-document-upload-file-input-upload-cover-letter')]")
cv_locator.send_keys(cv)
#time.sleep(random.uniform(4.5, 6.5))
elif len(self.get_elements("follow")) > 0:
elements = self.get_elements("follow")
for element in elements:
button = self.wait.until(EC.element_to_be_clickable(element))
button.click()
if len(self.get_elements("submit")) > 0:
elements = self.get_elements("submit")
for element in elements:
button = self.wait.until(EC.element_to_be_clickable(element))
button.click()
log.info("Application Submitted")
submitted = True
break
elif len(self.get_elements("error")) > 0:
elements = self.get_elements("error")
if "application was sent" in self.browser.page_source:
log.info("Application Submitted")
submitted = True
break
elif len(elements) > 0:
while len(elements) > 0:
log.info("Please answer the questions, waiting 5 seconds...")
time.sleep(5)
elements = self.get_elements("error")
for element in elements:
self.process_questions()
if "application was sent" in self.browser.page_source:
log.info("Application Submitted")
submitted = True
break
elif is_present(self.locator["easy_apply_button"]):
log.info("Skipping application")
submitted = False
break
continue
#add explicit wait
else:
log.info("Application not submitted")
time.sleep(2)
break
# self.process_questions()
elif len(self.get_elements("next")) > 0:
elements = self.get_elements("next")
for element in elements:
button = self.wait.until(EC.element_to_be_clickable(element))
button.click()
elif len(self.get_elements("review")) > 0:
elements = self.get_elements("review")
for element in elements:
button = self.wait.until(EC.element_to_be_clickable(element))
button.click()
elif len(self.get_elements("follow")) > 0:
elements = self.get_elements("follow")
for element in elements:
button = self.wait.until(EC.element_to_be_clickable(element))
button.click()
except Exception as e:
log.error(e)
log.error("cannot apply to this job")
pass
#raise (e)
return submitted
def process_questions(self):
time.sleep(1)
form = self.get_elements("fields") #self.browser.find_elements(By.CLASS_NAME, "jobs-easy-apply-form-section__grouping")
for field in form:
question = field.text
answer = self.ans_question(question.lower())
#radio button
if self.is_present(self.locator["radio_select"]):
try:
input = field.find_element(By.CSS_SELECTOR, "input[type='radio'][value={}]".format(answer))
input.execute_script("arguments[0].click();", input)
except Exception as e:
log.error(e)
continue
#multi select
elif self.is_present(self.locator["multi_select"]):
try:
input = field.find_element(self.locator["multi_select"])
input.send_keys(answer)
except Exception as e:
log.error(e)
continue
# text box
elif self.is_present(self.locator["text_select"]):
try:
input = field.find_element(self.locator["text_select"])
input.send_keys(answer)
except Exception as e:
log.error(e)
continue
elif self.is_present(self.locator["text_select"]):
pass
if "Yes" or "No" in answer: #radio button
try: #debug this
input = form.find_element(By.CSS_SELECTOR, "input[type='radio'][value={}]".format(answer))
form.execute_script("arguments[0].click();", input)
except:
pass
else:
input = form.find_element(By.CLASS_NAME, "artdeco-text-input--input")
input.send_keys(answer)
def ans_question(self, question): #refactor this to an ans.yaml file
answer = None
if "how many" in question:
answer = "1"
elif "experience" in question:
answer = "1"
elif "sponsor" in question:
answer = "No"
elif 'do you ' in question:
answer = "Yes"
elif "have you " in question:
answer = "Yes"
elif "US citizen" in question:
answer = "Yes"
elif "are you " in question:
answer = "Yes"
elif "salary" in question:
answer = self.salary
elif "can you" in question:
answer = "Yes"
elif "gender" in question:
answer = "Male"
elif "race" in question:
answer = "Wish not to answer"
elif "lgbtq" in question:
answer = "Wish not to answer"
elif "ethnicity" in question:
answer = "Wish not to answer"
elif "nationality" in question:
answer = "Wish not to answer"
elif "government" in question:
answer = "I do not wish to self-identify"
elif "are you legally" in question:
answer = "Yes"
else:
log.info("Not able to answer question automatically. Please provide answer")
#open file and document unanswerable questions, appending to it
answer = "user provided"
time.sleep(15)
# df = pd.DataFrame(self.answers, index=[0])
# df.to_csv(self.qa_file, encoding="utf-8")
log.info("Answering question: " + question + " with answer: " + answer)
# Append question and answer to the CSV
if question not in self.answers:
self.answers[question] = answer
# Append a new question-answer pair to the CSV file
new_data = pd.DataFrame({"Question": [question], "Answer": [answer]})
new_data.to_csv(self.qa_file, mode='a', header=False, index=False, encoding='utf-8')
log.info(f"Appended to QA file: '{question}' with answer: '{answer}'.")
return answer
def load_page(self, sleep=1):
scroll_page = 0
while scroll_page < 4000:
self.browser.execute_script("window.scrollTo(0," + str(scroll_page) + " );")
scroll_page += 500
time.sleep(sleep)
if sleep != 1:
self.browser.execute_script("window.scrollTo(0,0);")
time.sleep(sleep)
page = BeautifulSoup(self.browser.page_source, "lxml")
return page
def avoid_lock(self) -> None:
x, _ = pyautogui.position()
pyautogui.moveTo(x + 200, pyautogui.position().y, duration=1.0)
pyautogui.moveTo(x, pyautogui.position().y, duration=0.5)
pyautogui.keyDown('ctrl')
pyautogui.press('esc')
pyautogui.keyUp('ctrl')
time.sleep(0.5)
pyautogui.press('esc')
def next_jobs_page(self, position, location, jobs_per_page, experience_level=[]):
# Construct the experience level part of the URL
experience_level_str = ",".join(map(str, experience_level)) if experience_level else ""
experience_level_param = f"&f_E={experience_level_str}" if experience_level_str else ""
self.browser.get(
# URL for jobs page
"https://www.linkedin.com/jobs/search/?f_LF=f_AL&keywords=" +
position + location + "&start=" + str(jobs_per_page) + experience_level_param)
#self.avoid_lock()
log.info("Loading next job page?")
self.load_page()
return (self.browser, jobs_per_page)
# def finish_apply(self) -> None:
# self.browser.close()
if __name__ == '__main__':
with open("config.yaml", 'r') as stream:
try:
parameters = yaml.safe_load(stream)
except yaml.YAMLError as exc:
raise exc
assert len(parameters['positions']) > 0
assert len(parameters['locations']) > 0
assert parameters['username'] is not None
assert parameters['password'] is not None
assert parameters['phone_number'] is not None
if 'uploads' in parameters.keys() and type(parameters['uploads']) == list:
raise Exception("uploads read from the config file appear to be in list format" +
" while should be dict. Try removing '-' from line containing" +
" filename & path")
log.info({k: parameters[k] for k in parameters.keys() if k not in ['username', 'password']})
output_filename: list = [f for f in parameters.get('output_filename', ['output.csv']) if f is not None]
output_filename: list = output_filename[0] if len(output_filename) > 0 else 'output.csv'
blacklist = parameters.get('blacklist', [])
blackListTitles = parameters.get('blackListTitles', [])
uploads = {} if parameters.get('uploads', {}) is None else parameters.get('uploads', {})
for key in uploads.keys():
assert uploads[key] is not None
locations: list = [l for l in parameters['locations'] if l is not None]
positions: list = [p for p in parameters['positions'] if p is not None]
bot = EasyApplyBot(parameters['username'],
parameters['password'],
parameters['phone_number'],
parameters['salary'],
parameters['rate'],
uploads=uploads,
filename=output_filename,
blacklist=blacklist,
blackListTitles=blackListTitles,
experience_level=parameters.get('experience_level', [])
)
bot.start_apply(positions, locations)