I am trying to scrape information from this website example website
I need to get the version 2021 and search by code. Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions
ignored_exceptions=(NoSuchElementException,StaleElementReferenceException)
options = Options()
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=9515')
options.add_argument('--disable-setuid-sandbox')
options.add_argument("--start-maximized")
driver = webdriver.Chrome(service=Service("/usr/bin/chromedriver"), options=options)
url = "https://noc.esdc.gc.ca/"
driver.get(url)
search_by_code = WebDriverWait(driver, 10, ignored_exceptions=ignored_exceptions)\
.until(expected_conditions.presence_of_element_located((By.XPATH, "/html/body/main/div[2]/div/div/div/div/div/div/div/div/ul/li[2]/a")))
# click to activate this option
search_by_code.click()
text_area = WebDriverWait(driver, 10, ignored_exceptions=ignored_exceptions)\
.until(expected_conditions.presence_of_element_located((By.XPATH, "/html/body/main/div[2]/div/div/div/div/div/div/div/div/div/details[2]/div/div/form/div/div[2]/div/input")))
version = Select(WebDriverWait(driver, 10, ignored_exceptions=ignored_exceptions)\
.until(expected_conditions.presence_of_element_located((By.XPATH, "/html/body/main/div[2]/div/div/div/div/div/div/div/div/div/details[2]/div/div/form/div/div[1]/select"))))
search_button = driver.find_element(By.XPATH, '/html/body/main/div[2]/div/div/div/div/div/div/div/div/div/details[2]/div/div/form/div/div[2]/div/div/button')
# select version 2021
version.select_by_value('2021.0')
# click on text area
text_area.click()
# type the text
text_area.send_keys("10010 – Financial managers")
# click the button
search_button.click()
print(source = driver.current_url)
I am not sure what I have missed? I added some comments to describe the logic.
Financial managerswithout the prefix?