-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedineasyapply.py
executable file
·1026 lines (888 loc) · 43.8 KB
/
linkedineasyapply.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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import csv
import random
import time
import traceback
from datetime import date
from itertools import product
# import pyautogui
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
class LinkedinEasyApply:
def __init__(self, parameters, driver):
self.browser = driver
self.email = parameters['email']
self.password = parameters['password']
self.disable_lock = parameters['disableAntiLock']
self.company_blacklist = parameters.get('companyBlacklist', []) or []
self.title_blacklist = parameters.get('titleBlacklist', []) or []
self.poster_blacklist = parameters.get('posterBlacklist', []) or []
self.positions = parameters.get('positions', [])
self.locations = parameters.get('locations', [])
self.base_search_url = self.get_base_search_url(parameters)
self.seen_jobs = []
self.file_name = "output"
self.unprepared_questions_file_name = "unprepared_questions"
self.output_file_directory = parameters['outputFileDirectory']
self.resume_dir = parameters['uploads']['resume']
if 'coverLetter' in parameters['uploads']:
self.cover_letter_dir = parameters['uploads']['coverLetter']
else:
self.cover_letter_dir = ''
self.checkboxes = parameters.get('checkboxes', [])
self.university_gpa = parameters['universityGpa']
self.salary_minimum = parameters['salaryMinimum']
self.notice_period = parameters['NoticePeriod']
self.languages = parameters.get('languages', [])
self.experience = parameters.get('experience', [])
self.personal_info = parameters.get('personalInfo', [])
self.eeo = parameters.get('eeo', [])
self.experience_default = self.experience['default']
def login(self):
try:
self.browser.get("https://www.linkedin.com/login")
time.sleep(random.uniform(5, 10))
self.browser.find_element(By.ID, "username").send_keys(self.email)
self.browser.find_element(
By.ID, "password").send_keys(self.password)
self.browser.find_element(
By.CSS_SELECTOR, ".btn__primary--large").click()
time.sleep(random.uniform(5, 10))
except TimeoutException:
raise Exception("Could not login!")
def security_check(self):
current_url = self.browser.current_url
page_source = self.browser.page_source
if '/checkpoint/challenge/' in current_url or 'security check' in page_source:
input(
"Please complete the security check and press enter in this console when it is done.")
time.sleep(random.uniform(5.5, 10.5))
def start_applying(self):
searches = list(product(self.positions, self.locations))
# random.shuffle(searches)
page_sleep = 0
minimum_time = 15
# minimum_page_time = time.time() + minimum_time
minimum_page_time = 0
while True:
for (position, location) in searches:
print(position, location)
location_url = "&location=" + location
job_page_number = -1
total_pages = 0
flag = True
print("Starting the search for " +
position + " in " + location + ".")
try:
while True:
page_sleep += 1
job_page_number += 1
print("Going to job page " + str(job_page_number + 1))
self.next_job_page(position, location_url, job_page_number)
time.sleep(random.uniform(1.5, 3.5))
if flag is True:
total_pages = self.getting_total_pages()
print("Total Job Pages " + str(total_pages))
flag = False
if total_pages < job_page_number:
print("breaking because of total pages is less than the job_page_number")
break
self.apply_jobs(location)
print("Starting the application process for this page...")
print("Applying to jobs on this page has been completed!")
# time_left = minimum_page_time - time.time()
# if time_left > 0:
# print("Sleeping for " + str(time_left) + " seconds.")
# time.sleep(time_left)
# minimum_page_time = time.time() + minimum_time
# if page_sleep % 5 == 0:
# sleep_time = random.randint(500, 900)
# print("Sleeping for " + str(sleep_time / 60) + " minutes.")
# time.sleep(sleep_time)
# page_sleep += 1
except Exception as ex:
print(ex)
self.exception_save(traceback.format_exc())
pass
# time_left = minimum_page_time - time.time()
# if time_left > 0:
# print("Sleeping for " + str(time_left) + " seconds.")
# time.sleep(time_left)
# minimum_page_time = time.time() + minimum_time
# if page_sleep % 5 == 0:
# sleep_time = random.randint(500, 900)
# print("Sleeping for " + str(sleep_time / 60) + " minutes.")
# time.sleep(sleep_time)
# page_sleep += 1
def apply_jobs(self, location):
no_jobs_text = ""
try:
no_jobs_element = self.browser.find_element(By.CLASS_NAME,
'jobs-search-two-pane__no-results-banner--expand')
no_jobs_text = no_jobs_element.text
except:
pass
if 'No matching jobs found' in no_jobs_text:
raise Exception("No more jobs on this page")
if 'unfortunately, things aren' in self.browser.page_source.lower():
raise Exception("No more jobs on this page")
try:
job_results = self.browser.find_element(
By.CLASS_NAME, "jobs-search-results-list")
self.scroll_slow(job_results)
self.scroll_slow(job_results, step=300, reverse=True)
job_list = self.browser.find_elements(By.CLASS_NAME, 'scaffold-layout__list-container')[0].find_elements(
By.CLASS_NAME, 'jobs-search-results__list-item')
if len(job_list) == 0:
raise Exception("No job class elements found in page")
except:
raise Exception("No more jobs on this page")
if len(job_list) == 0:
raise Exception("No more jobs on this page")
for job_tile in job_list:
job_title, company, poster, job_location, apply_method, link = "", "", "", "", "", ""
try:
job_title = job_tile.find_element(
By.CLASS_NAME, 'job-card-list__title').text
job_el = job_tile.find_element(By.CLASS_NAME, 'job-card-list__title')
link = job_el.get_attribute('href').split('?')[0]
# link = job_tile.find_element(
# By.CLASS_NAME, 'job-card-list__title').get_attribute('href').split('?')[0]
except:
pass
try:
company = job_tile.find_element(
By.CLASS_NAME, 'job-card-container__company-name').text
except:
pass
try:
# get the name of the person who posted for the position, if any is listed
hiring_line = job_tile.find_element(
By.XPATH, '//span[contains(.,\' is hiring for this\')]')
hiring_line_text = hiring_line.text
name_terminating_index = hiring_line_text.find(
' is hiring for this')
if name_terminating_index != -1:
poster = hiring_line_text[:name_terminating_index]
except:
pass
try:
job_location = job_tile.find_element(
By.CLASS_NAME, 'job-card-container__metadata-item').text
except:
pass
try:
apply_method = job_tile.find_element(
By.CLASS_NAME, 'job-card-container__apply-method').text
except:
pass
contains_blacklisted_keywords = False
job_title_parsed = job_title.lower().split(' ')
for word in self.title_blacklist:
# print("inside the title_blacklist for loop")
if word.lower() in job_title_parsed:
contains_blacklisted_keywords = True
break
if company.lower() not in [word.lower() for word in self.company_blacklist] and \
poster.lower() not in [word.lower() for word in self.poster_blacklist] and \
contains_blacklisted_keywords is False and link not in self.seen_jobs:
try:
# job_el = job_tile.find_element(
# By.CLASS_NAME, 'job-card-list__title')
job_el.click()
time.sleep(random.uniform(3, 5))
try:
done_applying = self.apply_to_job
if done_applying:
print("Done applying to the job!")
else:
print('Already applied to the job!')
except:
temp = self.file_name
self.file_name = "failed"
print(
"Failed to apply to job! Please submit a bug report with this link: " + link)
print("Writing to the failed csv file...")
try:
self.write_to_file(
company, job_title, link, job_location, location)
except:
pass
self.file_name = temp
try:
self.write_to_file(
company, job_title, link, job_location, location)
except Exception as ex:
print(
"Could not write the job to the file! No special characters in the job title/company is allowed!")
self.exception_save(traceback.format_exc())
except Exception as ex:
print("Could not apply to the job!")
# traceback.print_exc()
self.exception_save(traceback.format_exc())
pass
else:
print("Job contains blacklisted keyword or company or poster name!")
self.seen_jobs += link
@property
def apply_to_job(self):
easy_apply_button = None
try:
easy_apply_button = self.browser.find_element(
By.CLASS_NAME, 'jobs-apply-button')
except:
return False
try:
job_description_area = self.browser.find_element(
By.CLASS_NAME, "jobs-search__job-details--container")
self.scroll_slow(job_description_area, end=1600)
self.scroll_slow(job_description_area, end=1600,
step=400, reverse=True)
except:
pass
print("Applying to the job....")
easy_apply_button.click()
button_text = ""
submit_application_text = 'submit application'
while submit_application_text not in button_text.lower():
try:
self.fill_up()
next_button = self.browser.find_element(
By.CLASS_NAME, "artdeco-button--primary")
button_text = next_button.text.lower()
if submit_application_text in button_text:
try:
self.unfollow()
except:
print("Failed to unfollow company!")
time.sleep(random.uniform(1.5, 2.5))
next_button.click()
time.sleep(random.uniform(3.0, 5.0))
if 'whole' in self.browser.page_source.lower() \
or 'please enter a valid answer' in self.browser.page_source.lower() \
or 'file is required' in self.browser.page_source.lower() \
or 'larger than 0.0' in self.browser.page_source.lower() \
or 'Please make a selection' in self.browser.page_source.lower():
raise Exception(
"Failed answering required questions or uploading required files.")
except:
self.exception_save(traceback.format_exc())
self.browser.find_element(
By.CLASS_NAME, 'artdeco-modal__dismiss').click()
time.sleep(random.uniform(3, 5))
self.browser.find_elements(
By.CLASS_NAME, 'artdeco-modal__confirm-dialog-btn')[1].click()
time.sleep(random.uniform(3, 5))
raise Exception("Failed to apply to job!")
closed_notification = False
time.sleep(random.uniform(3, 5))
try:
self.browser.find_element(
By.CLASS_NAME, 'artdeco-modal__dismiss').click()
closed_notification = True
except:
pass
try:
self.browser.find_element(
By.CLASS_NAME, 'artdeco-toast-item__dismiss').click()
closed_notification = True
except:
pass
time.sleep(random.uniform(3, 5))
if closed_notification is False:
raise Exception("Could not close the applied confirmation window!")
return True
def home_address(self, element):
try:
groups = element.find_elements(
By.CLASS_NAME, 'jobs-easy-apply-form-section__grouping')
if len(groups) > 0:
for group in groups:
lb = group.find_element(By.TAG_NAME, 'label').text.lower()
input_field = group.find_element(By.TAG_NAME, 'input')
if 'street' in lb:
self.enter_text(
input_field, self.personal_info['Street address'])
elif 'city' in lb:
self.enter_text(
input_field, self.personal_info['City'])
time.sleep(3)
input_field.send_keys(Keys.DOWN)
input_field.send_keys(Keys.RETURN)
elif 'zip' in lb or 'postal' in lb:
self.enter_text(input_field, self.personal_info['Zip'])
elif 'state' in lb or 'province' in lb:
self.enter_text(
input_field, self.personal_info['State'])
else:
pass
except:
pass
def get_answer(self, question):
if self.checkboxes[question]:
return 'yes'
else:
return 'no'
def additional_questions(self):
# pdb.set_trace()
frm_el = self.browser.find_elements(
By.CLASS_NAME, 'jobs-easy-apply-form-section__grouping')
if len(frm_el) > 0:
for el in frm_el:
# Radio check
try:
question = el.find_element(
By.CLASS_NAME, 'jobs-easy-apply-form-element')
radios = question.find_elements(
By.CLASS_NAME, 'fb-text-selectable__option')
if len(radios) == 0:
raise Exception("No radio found in element")
radio_text = el.text.lower()
radio_options = [text.text.lower() for text in radios]
answer = "yes"
if 'driver\'s licence' in radio_text or 'driver\'s license' in radio_text:
answer = self.get_answer('driversLicence')
elif 'gender' in radio_text or 'veteran' in radio_text or 'race' in radio_text or 'disability' in radio_text or 'latino' in radio_text:
answer = ""
for option in radio_options:
if 'prefer' in option.lower() or 'decline' in option.lower() or 'don\'t' in option.lower() or 'specified' in option.lower() or 'none' in option.lower():
answer = option
if answer == "":
answer = radio_options[len(radio_options) - 1]
elif 'assessment' in radio_text:
answer = self.get_answer("assessment")
elif 'north korea' in radio_text:
answer = 'no'
elif 'previously employ' in radio_text or 'previous employ' in radio_text:
answer = 'no'
elif 'authorized' in radio_text or 'authorised' in radio_text or 'legally' in radio_text:
answer = self.get_answer('legallyAuthorized')
elif 'urgent' in radio_text:
answer = self.get_answer('urgentFill')
elif 'commut' in radio_text:
answer = self.get_answer('commute')
elif 'remote' in radio_text:
answer = self.get_answer('remote')
elif 'background check' in radio_text:
answer = self.get_answer('backgroundCheck')
elif 'drug test' in radio_text:
answer = self.get_answer('drugTest')
elif 'level of education' in radio_text:
for degree in self.checkboxes['degreeCompleted']:
if degree.lower() in radio_text:
answer = "yes"
break
elif 'experience' in radio_text:
for experience in self.experience:
if experience.lower() in radio_text:
answer = "yes"
break
elif 'data retention' in radio_text:
answer = 'no'
elif 'sponsor' in radio_text:
answer = self.get_answer('requireVisa')
else:
answer = radio_options[len(radio_options) - 1]
self.record_unprepared_question("radio", radio_text)
i = 0
to_select = None
for radio in radios:
if answer in radio.text.lower():
to_select = radios[i]
i += 1
if to_select is None:
to_select = radios[len(radios) - 1]
self.radio_select(to_select, answer, len(radios) > 2)
if radios != []:
continue
except:
pass
# Questions check
try:
question = el.find_element(
By.CLASS_NAME, 'jobs-easy-apply-form-element')
question_text = question.find_element(
By.TAG_NAME, 'label').text.lower()
txt_field_visible = False
try:
txt_field = question.find_element(By.TAG_NAME, 'input')
txt_field_visible = True
except:
try:
txt_field = question.find_element(
By.TAG_NAME, 'textarea') # TODO: Test textarea
txt_field_visible = True
except:
raise Exception(
"Could not find textarea or input tag for question")
text_field_type = txt_field.get_attribute('type').lower()
if 'numeric' in text_field_type: # TODO: test numeric type
text_field_type = 'numeric'
elif 'text' in text_field_type:
text_field_type = 'text'
else:
raise Exception(
"Could not determine input type of input field!")
to_enter = ''
if 'experience' in question_text:
no_of_years = None
for experience in self.experience:
if experience.lower() in question_text:
no_of_years = self.experience[experience]
break
if no_of_years is None:
self.record_unprepared_question(
text_field_type, question_text)
no_of_years = self.experience_default
to_enter = no_of_years
elif 'grade point average' in question_text:
to_enter = self.university_gpa
elif 'first name' in question_text:
to_enter = self.personal_info['First Name']
elif 'last name' in question_text:
to_enter = self.personal_info['Last Name']
elif 'name' in question_text:
to_enter = self.personal_info['First Name'] + \
" " + self.personal_info['Last Name']
elif 'pronouns' in question_text:
to_enter = self.personal_info['Pronouns']
elif 'phone' in question_text:
to_enter = self.personal_info['Mobile Phone Number']
elif 'linkedin' in question_text:
to_enter = self.personal_info['Linkedin']
elif 'website' in question_text or 'github' in question_text or 'portfolio' in question_text:
to_enter = self.personal_info['Website']
elif 'salary' in question_text.lower() or 'ctc' in question_text.lower():
to_enter = self.salary_minimum
elif 'period' in question_text.lower():
to_enter = self.notice_period
else:
if text_field_type == 'numeric':
to_enter = 0
else:
to_enter = " "
self.record_unprepared_question(
text_field_type, question_text)
if text_field_type == 'numeric':
if not isinstance(to_enter, (int, float)):
to_enter = 0
elif to_enter == '':
to_enter = " "
self.enter_text(txt_field, to_enter)
continue
except:
pass
# Date Check
try:
date_picker = el.find_element(
By.CLASS_NAME, 'artdeco-datepicker__input ')
date_picker.clear()
date_picker.send_keys(date.today().strftime("%m/%d/%y"))
time.sleep(3)
date_picker.send_keys(Keys.RETURN)
time.sleep(2)
continue
except:
pass
# Dropdown check
try:
question = el.find_element(
By.CLASS_NAME, 'jobs-easy-apply-form-element')
question_text = question.find_element(
By.TAG_NAME, 'label').text.lower()
dropdown_field = question.find_element(
By.TAG_NAME, 'select')
select = Select(dropdown_field)
options = [options.text for options in select.options]
if 'proficiency' in question_text:
proficiency = "Conversational"
for language in self.languages:
if language.lower() in question_text:
proficiency = self.languages[language]
break
self.select_dropdown(dropdown_field, proficiency)
elif 'assessment' in question_text:
answer = self.get_answer('assessment')
choice = ""
for option in options:
if answer == 'yes':
choice = option
else:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'commut' in question_text:
answer = self.get_answer('commute')
choice = ""
for option in options:
if answer == 'yes':
choice = option
else:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'country code' in question_text:
self.select_dropdown(
dropdown_field, self.personal_info['Phone Country Code'])
elif 'north korea' in question_text:
choice = ""
for option in options:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'previously employed' in question_text or 'previous employment' in question_text:
choice = ""
for option in options:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'sponsor' in question_text:
answer = self.get_answer('requireVisa')
choice = ""
for option in options:
if answer == 'yes':
choice = option
else:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'authorized' in question_text or 'authorised' in question_text:
answer = self.get_answer('legallyAuthorized')
choice = ""
for option in options:
if answer == 'yes':
# find some common words
choice = option
else:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'citizenship' in question_text:
answer = self.get_answer('legallyAuthorized')
choice = ""
for option in options:
if answer == 'yes':
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'clearance' in question_text:
answer = self.get_answer('clearance')
choice = ""
for option in options:
if answer == 'yes':
# find some common words
choice = option
else:
if 'no' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'gender' in question_text or 'veteran' in question_text or 'race' in question_text or 'disability' in question_text or 'latino' in question_text:
choice = ""
for option in options:
if 'prefer' in option.lower() or 'decline' in option.lower() or 'don\'t' in option.lower() or 'specified' in option.lower() or 'none' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
elif 'email' in question_text:
continue # assume email address is filled in properly by default
elif 'experience' in question_text or 'understanding' in question_text or 'familiar' in question_text or 'comfortable' in question_text or 'able to' in question_text:
answer = 'no'
for experience in self.experience:
if experience.lower() in question_text and self.experience[experience] > 0:
answer = 'yes'
break
if answer == 'no':
# record unlisted experience as unprepared questions
self.record_unprepared_question(
"dropdown", question_text)
choice = ""
for option in options:
if answer in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
else:
choice = ""
for option in options:
if 'yes' in option.lower():
choice = option
if choice == "":
choice = options[len(options) - 1]
self.select_dropdown(dropdown_field, choice)
self.record_unprepared_question(
"dropdown", question_text)
continue
except:
pass
# Checkbox check for agreeing to terms and service
try:
question = el.find_element(
By.CLASS_NAME, 'jobs-easy-apply-form-element')
clickable_checkbox = question.find_element(
By.TAG_NAME, 'label')
clickable_checkbox.click()
except:
pass
def unfollow(self):
try:
follow_checkbox = self.browser.find_element(By.XPATH,
"//label[contains(.,\'to stay up to date with their page.\')]").click()
follow_checkbox.click()
except:
pass
def send_resume(self):
try:
check = self.browser.find_elements(By.CLASS_NAME, 'mt2')
if check is not None:
return
file_upload_elements = (By.CSS_SELECTOR, "input[name='file']")
if len(self.browser.find_elements(file_upload_elements[0], file_upload_elements[1])) > 0:
input_buttons = self.browser.find_elements(
file_upload_elements[0], file_upload_elements[1])
if len(input_buttons) == 0:
raise Exception("No input elements found in element")
for upload_button in input_buttons:
upload_type = upload_button.find_element(By.XPATH, "..").find_element(By.XPATH,
"preceding-sibling::*")
if 'resume' in upload_type.text.lower():
upload_button.send_keys(self.resume_dir)
elif 'cover' in upload_type.text.lower():
if self.cover_letter_dir != '':
upload_button.send_keys(self.cover_letter_dir)
elif 'required' in upload_type.text.lower():
upload_button.send_keys(self.resume_dir)
except:
print("Failed to upload resume or cover letter!")
pass
def enter_text(self, element, text):
element.clear()
element.send_keys(text)
def select_dropdown(self, element, text):
select = Select(element)
select.select_by_visible_text(text)
# Radio Select
def radio_select(self, element, label_text, clickLast=False):
label = element.find_element(By.TAG_NAME, 'label')
if label_text in label.text.lower() or clickLast == True:
label.click()
else:
pass
# Contact info fill-up
def contact_info(self):
frm_el = self.browser.find_elements(
By.CLASS_NAME, 'jobs-easy-apply-form-section__grouping')
if len(frm_el) > 0:
for el in frm_el:
text = el.text.lower()
if 'email address' in text:
continue
elif 'phone number' in text:
try:
country_code_picker = el.find_element(By.XPATH,
'//select[contains(@id,"phoneNumber")][contains(@id,"country")]')
self.select_dropdown(
country_code_picker, self.personal_info['Phone Country Code'])
except:
print("Country code " + self.personal_info[
'Phone Country Code'] + " not found! Make sure it is exact.")
self.exception_save(traceback.format_exc())
# print(e)
try:
phone_number_field = el.find_element(By.XPATH,
'//input[contains(@id,"phoneNumber")][contains(@id,"nationalNumber")]')
self.enter_text(
phone_number_field, self.personal_info['Mobile Phone Number'])
except:
print("Could not input phone number:")
self.exception_save(traceback.format_exc())
# print(e)
def fill_up(self):
try:
easy_apply_content = self.browser.find_element(
By.CLASS_NAME, 'jobs-easy-apply-content')
# b4 = easy_apply_content.find_element(By.CLASS_NAME, 'pb4')
pb4 = easy_apply_content.find_elements(By.CLASS_NAME, 'pb4')
if len(pb4) == 0:
raise Exception("No pb4 class elements found in element")
if len(pb4) > 0:
for pb in pb4:
try:
label = pb.find_element(By.TAG_NAME, 'h3').text.lower()
try:
self.additional_questions()
except:
pass
try:
self.send_resume()
except:
pass
if 'home address' in label:
self.home_address(pb)
elif 'contact info' in label:
self.contact_info()
except:
pass
except:
pass
def write_to_file(self, company, job_title, link, location, search_location):
to_write = [company, job_title, link, location]
# file_path = self.output_file_directory + self.file_name + search_location + ".csv"
file_path = self.file_name + search_location + ".csv"
with open(file_path, 'a') as f:
writer = csv.writer(f)
writer.writerow(to_write)
def record_unprepared_question(self, answer_type, question_text):
to_write = [answer_type, question_text]
file_path = self.unprepared_questions_file_name + ".csv"
try:
with open(file_path, 'a') as f:
writer = csv.writer(f)
writer.writerow(to_write)
except:
print(
"Could not write the unprepared question to the file! No special characters in the question is "
"allowed: ")
print(question_text)
def scroll_slow(self, scrollable_element, start=0, end=3600, step=100, reverse=False):
if reverse:
start, end = end, start
step = -step
for i in range(start, end, step):
self.browser.execute_script(
"arguments[0].scrollTo(0, {})".format(i), scrollable_element)
time.sleep(random.uniform(1.0, 2.6))
def avoid_lock(self):
if self.disable_lock:
return
# pyautogui.keyDown('ctrl')
# pyautogui.press('esc')
# pyautogui.keyUp('ctrl')
# time.sleep(1.0)
# pyautogui.press('esc')
def get_base_search_url(self, parameters):
remote_url = ""
if parameters['remote']:
remote_url = "f_CF=f_WRA"
level = 1
experience_level = parameters.get('experienceLevel', [])
experience_url = "f_E="
for key in experience_level.keys():
if experience_level[key]:
experience_url += "%2C" + str(level)
level += 1
distance_url = "?distance=" + str(parameters['distance'])
job_types_url = "f_JT="
job_types = parameters.get('jobTypes', [])
for key in job_types:
if job_types[key]:
job_types_url += "%2C" + key[0].upper()
# Industry startpoint
industry_url = "f_I="
industry = {"Human Resources Services": "137",
"Staffing and Recruiting": "104",
"Technology, Information and Internet": "6",
"Software Development": "4",
"Computer Hardware Manufacturing": "3",
"Banking": "41", "Insurance": "42",
"Computer and Network Security": "118",
"Retail": "27",
"Investment Management": "46",
"Financial Services": "43",
"Wireless Services": "119",
"Semiconductor Manufacturing": "7",
"IT Services and IT Consulting": "96",
"Telecommunications": "8"
}
industry_table = parameters.get('Industry', [])
for key in industry_table.keys():
if industry_table[key]:
industry_url += "%2C" + industry[key]
# industry endpoint
# Job_function startpoint
job_function_url = "f_F="
job_function = {"Research": "rsch",
"Quality Assurance": "qa",
"Sales": "sale",
"Consulting": "cnsl",
"Engineering": "eng",
"Information Technology": "it",
"Business Development": "bd",
"Management": "mgmt",
"Art/Creative": "art",
"Other": "othr",
"Design": "dsgn",
"Project Management": "prjm"
}
job_function_table = parameters.get('Job_function', [])
for key in job_function_table.keys():
if job_function_table[key]:
job_function_url += "%2C" + job_function[key]
# Job_function endpoint
date_url = ""
dates = {"all time": "", "month": "&f_TPR=r2592000",
"week": "&f_TPR=r604800", "24 hours": "&f_TPR=r86400"}
date_table = parameters.get('date', [])
for key in date_table.keys():
if date_table[key]:
date_url = dates[key]
break
easy_apply_url = "&f_LF=f_AL"
extra_search_terms = [distance_url, remote_url, job_types_url,
experience_url, industry_url, job_function_url]
extra_search_terms_str = '&'.join(
term for term in extra_search_terms if len(term) > 0) + easy_apply_url + date_url
return extra_search_terms_str
def next_job_page(self, position, location, job_page):
self.browser.get("https://www.linkedin.com/jobs/search/" + self.base_search_url +
"&keywords=" + position + location + "&start=" + str(job_page * 25))
self.avoid_lock()
def getting_total_pages(self):
hidden_li_text = self.browser.execute_script("return document.querySelector('.artdeco-pagination__pages--number li:last-child').textContent;")
# print("Text of hidden <li> tag:", hidden_li_text)
# ul_element = self.browser.find_element(By.CLASS_NAME, "artdeco-pagination__pages")
# li_elements = ul_element.find_elements(By.CLASS_NAME, "artdeco-pagination__indicator")
# page_numbers = []
#
# for li_element in li_elements:
# try:
# span = li_element.find_element(By.TAG_NAME, "span")
# number = span.text