After hours looking for an answer online I give up and require your help. My code below work very fine with this version.
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time
import csv
url = "https://www.welcometothejungle.com/fr/jobs?query=&groupBy=job&sortBy=mostRelevant&page=1&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Logiciels&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Big+Data&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=SaaS+%2F+Cloud+Services&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Intelligence+artificielle+%2F+Machine+Learning&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Cybers%C3%A9curit%C3%A9&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Application+mobile&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Objets+connect%C3%A9s&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Robotique&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Blockchain"
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
driver.maximize_window()
arrTitleText = []
arrCompanyText = []
jobTitle = driver.find_elements(By.CLASS_NAME, "ais-Highlight-nonHighlighted")
companyName = driver.find_elements(By.CLASS_NAME, "sc-7dlxn3-6")
for i in range(len(jobTitle)):
arrTitleText.append(jobTitle[i])
arrCompanyText.append(companyName[i])
arrGlobalText = []
for i in range(len(arrTitleText)):
arrGlobalText.append([arrTitleText[i].text, arrCompanyText[i].text])
print(arrGlobalText)
But as soon as I add the while loop and the next button, i have this error message, and I really can't find out what is happening.
You have the error version below.
Can someone have a clue or something ?
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time
import csv
url = "https://www.welcometothejungle.com/fr/jobs?query=&groupBy=job&sortBy=mostRelevant&page=1&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Logiciels&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Big+Data&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=SaaS+%2F+Cloud+Services&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Intelligence+artificielle+%2F+Machine+Learning&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Cybers%C3%A9curit%C3%A9&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Application+mobile&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Objets+connect%C3%A9s&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Robotique&refinementList%5Bsectors_name.fr.Tech%5D%5B%5D=Blockchain"
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
driver.maximize_window()
arrTitleText = []
arrCompanyText = []
jobTitle = driver.find_elements(By.CLASS_NAME, "ais-Highlight-nonHighlighted")
companyName = driver.find_elements(By.CLASS_NAME, "sc-7dlxn3-6")
p = 1
while p < 10:
for i in range(len(jobTitle)):
arrTitleText.append(jobTitle[i])
arrCompanyText.append(companyName[i])
arrGlobalText = []
for i in range(len(arrTitleText)):
arrGlobalText.append([arrTitleText[i].text, arrCompanyText[i].text])
nextButton = driver.find_elements(By.CLASS_NAME, 'ais-Pagination-item--nextPage')
nextButton[0].click()
p = p + 1
print(arrGlobalText)
Here is the error code:
DevTools listening on ws://127.0.0.1:56632/devtools/browser/96d3c2aa-ad19-4569-b221-cb79793f9c6c
Traceback (most recent call last):
File "C:\Users\Mohamed\Bureau\DEV\python\scraping\WTTJ\scrapwttj.py", line 23, in <module>
arrGlobalText.append([arrTitleText[i].text, arrCompanyText[i].text])
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 77, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 710, in _execute
return self._parent.execute(command, params)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
self.error_handler.check_response(response)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=103.0.5060.114)