@@ -244,7 +244,6 @@ def start_applying(self):
244244 def get_jobs_from_page (self , scroll = False ):
245245
246246 try :
247-
248247 no_jobs_element = self .driver .find_element (By .CLASS_NAME , 'jobs-search-two-pane__no-results-banner--expand' )
249248 if 'No matching jobs found' in no_jobs_element .text or 'unfortunately, things aren' in self .driver .page_source .lower ():
250249 logger .debug ("No matching jobs found on this page, skipping." )
@@ -255,22 +254,23 @@ def get_jobs_from_page(self, scroll=False):
255254
256255 try :
257256 # 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 )
257+ jobs_xpath_query = "//ul[contains(@class, 'scaffold-layout__list-container')]"
258+ jobs_container = self .driver .find_element (By .XPATH , jobs_xpath_query )
260259
261260 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 )} ' )
261+ jobs_container_scrolableElement = jobs_container .find_element (By .XPATH ,".." )
262+ logger .warning (f'is scrollable: { browser_utils .is_scrollable (jobs_container_scrolableElement )} ' )
263+
264+ browser_utils .scroll_slow (self .driver , jobs_container_scrolableElement )
265+ browser_utils .scroll_slow (self .driver , jobs_container_scrolableElement , step = 300 , reverse = True )
264266
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+ job_element_list = jobs_container .find_elements (By .XPATH , ".//li[contains(@class, 'jobs-search-results__list-item') and contains(@class, 'ember-view')]" )
267268
268- job_list_elements = job_results .find_elements (By .XPATH , ".//li[contains(@class, 'jobs-search-results__list-item') and contains(@class, 'ember-view')]" )
269- if not job_list_elements :
269+ if not job_element_list :
270270 logger .debug ("No job class elements found on page, skipping." )
271271 return []
272272
273- return job_list_elements
273+ return job_element_list
274274
275275 except NoSuchElementException as e :
276276 logger .warning (f'No job results found on the page. \n expection: { traceback .format_exc ()} ' )
@@ -281,20 +281,9 @@ def get_jobs_from_page(self, scroll=False):
281281 return []
282282
283283 def read_jobs (self ):
284- try :
285- no_jobs_element = self .driver .find_element (By .CLASS_NAME , 'jobs-search-two-pane__no-results-banner--expand' )
286- if 'No matching jobs found' in no_jobs_element .text or 'unfortunately, things aren' in self .driver .page_source .lower ():
287- raise Exception ("No more jobs on this page" )
288- except NoSuchElementException :
289- pass
290-
291- job_results = self .driver .find_element (By .CLASS_NAME , "jobs-search-results-list" )
292- browser_utils .scroll_slow (self .driver , job_results )
293- browser_utils .scroll_slow (self .driver , job_results , step = 300 , reverse = True )
294- job_list_elements = self .driver .find_elements (By .CLASS_NAME , 'scaffold-layout__list-container' )[0 ].find_elements (By .CLASS_NAME , 'jobs-search-results__list-item' )
295- if not job_list_elements :
296- raise Exception ("No job class elements found on page" )
297- job_list = [self .job_tile_to_job (job_element ) for job_element in job_list_elements ]
284+
285+ job_element_list = self .get_jobs_from_page ()
286+ job_list = [self .job_tile_to_job (job_element ) for job_element in job_element_list ]
298287 for job in job_list :
299288 if self .is_blacklisted (job .title , job .company , job .link , job .location ):
300289 logger .info (f"Blacklisted { job .title } at { job .company } in { job .location } , skipping..." )
@@ -307,21 +296,9 @@ def read_jobs(self):
307296 continue
308297
309298 def apply_jobs (self ):
310- try :
311- no_jobs_element = self .driver .find_element (By .CLASS_NAME , 'jobs-search-two-pane__no-results-banner--expand' )
312- if 'No matching jobs found' in no_jobs_element .text or 'unfortunately, things aren' in self .driver .page_source .lower ():
313- logger .debug ("No matching jobs found on this page, skipping" )
314- return
315- except NoSuchElementException :
316- pass
317-
318- job_list_elements = self .get_jobs_from_page ()
299+ job_element_list = self .get_jobs_from_page ()
319300
320- if not job_list_elements :
321- logger .debug ("No job class elements found on page, skipping" )
322- return
323-
324- job_list = [self .job_tile_to_job (job_element ) for job_element in job_list_elements ]
301+ job_list = [self .job_tile_to_job (job_element ) for job_element in job_element_list ]
325302
326303 for job in job_list :
327304
@@ -494,7 +471,7 @@ def job_tile_to_job(self, job_tile) -> Job:
494471 logger .debug (f"Job link extracted: { job .link } " )
495472 except NoSuchElementException :
496473 logger .warning ("Job link is missing." )
497-
474+
498475 try :
499476 job .company = job_tile .find_element (By .XPATH , ".//div[contains(@class, 'artdeco-entity-lockup__subtitle')]//span" ).text
500477 logger .debug (f"Job company extracted: { job .company } " )
@@ -517,11 +494,17 @@ def job_tile_to_job(self, job_tile) -> Job:
517494 except NoSuchElementException :
518495 logger .warning ("Job location is missing." )
519496
497+
520498 try :
521- job . apply_method = job_tile .find_element (By .CLASS_NAME , 'job-card-container__apply-method' ).text
499+ job_state = job_tile .find_element (By .XPATH , ".//ul[contains(@class, 'job-card-list__footer-wrapper')]//li[contains(@class, 'job-card- container__apply-method')]" ).text
522500 except NoSuchElementException as e :
523- job .apply_method = "Applied"
524- logger .warning (f'Apply method not found, assuming \' Applied\' . { e } { traceback .format_exc ()} ' )
501+ try :
502+ # Fetching state when apply method is not found
503+ job_state = job_tile .find_element (By .XPATH , ".//ul[contains(@class, 'job-card-list__footer-wrapper')]//li[contains(@class, 'job-card-container__footer-job-state')]" ).text
504+ job .apply_method = "Applied"
505+ logger .warning (f'Apply method not found, state { job_state } . { e } { traceback .format_exc ()} ' )
506+ except NoSuchElementException as e :
507+ logger .warning (f'Apply method and state not found. { e } { traceback .format_exc ()} ' )
525508
526509 return job
527510
0 commit comments