# Try multiple selectors in case the primary one fails
date_element1 await job.querySelector('span [data-testid="myJobsStateDate"].css-qvloho')
date_element2 = await job.querySelector('h2 + div span.iaTextBlack')
date_element3 await job.querySelector('div.jobSectionInfo div.metadata span.date')
date_element4 await job.querySelector('div.job_section.metadata.date')
date_element5 await job.querySelector('div[data-testid="job-snippet"] span.date')
date_posted = None
if date_element1:
date_posted await page.evaluate('(element) => element ? element.textContent.trim(): null', date_element1)
elif date_element2:
date_posted await page.evaluate('(element) => element ? element.textContent.trim(): null', date_element2)
elif date_element3:
date_posted await page.evaluate('(element) => element ? element.textContent.trim() null', date_element3)
elif date_element4:
date_posted await page.evaluate('(element) => element ? element.textContent.trim() null', date_element4)
elif date_element5:
date_posted await page.evaluate('(element) => element ? element.textContent.trim(): null', date_element5)
else:
#No matching selector found, set date_posted to None
date_posted = None
print(date_posted)
I need help extracting "Posted x days ago" from the following code using Pyppeteer in Python. I have attached a screenshot of the HTML code as well as a screenshot of my code which is not working/not retrieving any data. This must be done in python.