4
4
import time
5
5
from itertools import product
6
6
from pathlib import Path
7
+ import traceback
7
8
from turtle import color
8
9
9
10
from inputimeout import inputimeout , TimeoutOccurred
13
14
14
15
from ai_hawk .linkedIn_easy_applier import AIHawkEasyApplier
15
16
from config import JOB_MAX_APPLICATIONS , JOB_MIN_APPLICATIONS , MINIMUM_WAIT_TIME_IN_SECONDS
17
+ import job
16
18
from src .job import Job
17
19
from src .logging import logger
18
20
@@ -155,7 +157,7 @@ def start_applying(self):
155
157
logger .debug ("Starting the application process for this page..." )
156
158
157
159
try :
158
- jobs = self .get_jobs_from_page ()
160
+ jobs = self .get_jobs_from_page (scroll = True )
159
161
if not jobs :
160
162
logger .debug ("No more jobs found on this page. Exiting loop." )
161
163
break
@@ -166,7 +168,7 @@ def start_applying(self):
166
168
try :
167
169
self .apply_jobs ()
168
170
except Exception as e :
169
- logger .error (f"Error during job application: { e } " )
171
+ logger .error (f"Error during job application: { e } { traceback . format_exc () } " )
170
172
continue
171
173
172
174
logger .debug ("Applying to jobs on this page has been completed!" )
@@ -239,7 +241,7 @@ def start_applying(self):
239
241
time .sleep (sleep_time )
240
242
page_sleep += 1
241
243
242
- def get_jobs_from_page (self ):
244
+ def get_jobs_from_page (self , scroll = False ):
243
245
244
246
try :
245
247
@@ -252,24 +254,30 @@ def get_jobs_from_page(self):
252
254
pass
253
255
254
256
try :
255
- job_results = self . driver . find_element ( By . CLASS_NAME , "jobs-search-results-list" )
256
- browser_utils . scroll_slow ( self . driver , job_results )
257
- browser_utils . scroll_slow ( self .driver , job_results , step = 300 , reverse = True )
257
+ # XPath query to find the ul tag with class scaffold-layout__list-container
258
+ job_results_xpath_query = "//ul[contains(@class, 'scaffold-layout__list-container')]"
259
+ job_results = self .driver . find_element ( By . XPATH , job_results_xpath_query )
258
260
259
- job_list_elements = self .driver .find_elements (By .CLASS_NAME , 'scaffold-layout__list-container' )[
260
- 0 ].find_elements (By .CLASS_NAME , 'jobs-search-results__list-item' )
261
+ if scroll :
262
+ job_results_scrolableElament = job_results .find_element (By .XPATH ,".." )
263
+ logger .warning (f'is scrollable: { browser_utils .is_scrollable (job_results_scrolableElament )} ' )
264
+
265
+ browser_utils .scroll_slow (self .driver , job_results_scrolableElament )
266
+ browser_utils .scroll_slow (self .driver , job_results_scrolableElament , step = 300 , reverse = True )
267
+
268
+ job_list_elements = job_results .find_elements (By .XPATH , ".//li[contains(@class, 'jobs-search-results__list-item') and contains(@class, 'ember-view')]" )
261
269
if not job_list_elements :
262
270
logger .debug ("No job class elements found on page, skipping." )
263
271
return []
264
272
265
273
return job_list_elements
266
274
267
- except NoSuchElementException :
268
- logger .debug ( " No job results found on the page." )
275
+ except NoSuchElementException as e :
276
+ logger .warning ( f' No job results found on the page. \n expection: { traceback . format_exc () } ' )
269
277
return []
270
278
271
279
except Exception as e :
272
- logger .error (f"Error while fetching job elements: { e } " )
280
+ logger .error (f"Error while fetching job elements: { e } { traceback . format_exc () } " )
273
281
return []
274
282
275
283
def read_jobs (self ):
@@ -307,8 +315,7 @@ def apply_jobs(self):
307
315
except NoSuchElementException :
308
316
pass
309
317
310
- job_list_elements = self .driver .find_elements (By .CLASS_NAME , 'scaffold-layout__list-container' )[
311
- 0 ].find_elements (By .CLASS_NAME , 'jobs-search-results__list-item' )
318
+ job_list_elements = self .get_jobs_from_page ()
312
319
313
320
if not job_list_elements :
314
321
logger .debug ("No job class elements found on page, skipping" )
@@ -489,10 +496,10 @@ def job_tile_to_job(self, job_tile) -> Job:
489
496
logger .warning ("Job link is missing." )
490
497
491
498
try :
492
- job .company = job_tile .find_element (By .CLASS_NAME , 'job-card-container__primary-description' ).text
499
+ job .company = job_tile .find_element (By .XPATH , ".//div[contains(@class, 'artdeco-entity-lockup__subtitle')]//span" ).text
493
500
logger .debug (f"Job company extracted: { job .company } " )
494
- except NoSuchElementException :
495
- logger .warning (" Job company is missing." )
501
+ except NoSuchElementException as e :
502
+ logger .warning (f' Job company is missing. { e } { traceback . format_exc () } ' )
496
503
497
504
# Extract job ID from job url
498
505
try :
@@ -512,9 +519,9 @@ def job_tile_to_job(self, job_tile) -> Job:
512
519
513
520
try :
514
521
job .apply_method = job_tile .find_element (By .CLASS_NAME , 'job-card-container__apply-method' ).text
515
- except NoSuchElementException :
522
+ except NoSuchElementException as e :
516
523
job .apply_method = "Applied"
517
- logger .warning (" Apply method not found, assuming 'Applied'." )
524
+ logger .warning (f' Apply method not found, assuming \ ' Applied\' . { e } { traceback . format_exc () } ' )
518
525
519
526
return job
520
527
0 commit comments