I have the following function:
def get_info(url):
options = webdriver.ChromeOptions()
options.headless = True
chrome_browser = webdriver.Chrome('./chromedriver', chrome_options=options)
chrome_browser.get(url)
name = chrome_browser.find_element_by_xpath("//h1[contains(@class,'text-center medium-text-left')]").text
winter = WebDriverWait(chrome_browser, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="main-content"]/div[1]/div[1]/div/div[2]/div[5]/div['
'2]/div/div[1]/div[3]/div')))
chrome_browser.quit()
return winter, name
I want to get the width percentage from the winter/spring/summer etc charts on this site: https://www.fragrantica.com/perfume/Christian-Dior/Sauvage-Eau-de-Parfum-48100.html
So I want this function to return the name of the fragrance and the winter row on the HTML page. The season ratings seem to load a bit slower on the site so I've tried to add wait until the HTML row appears. When I click inspect on the winter ratings chart I am given this element:
<div style="border-radius: 0.2rem; height: 0.3rem; background: rgb(120, 214, 240); width: 90.3491%; opacity: 1;"></div>
Firstly, BeautifulSoup did not find it so I tried Selenium. Selenium does not find it, and when using the WebDriverWait it just shows me this error:
Traceback (most recent call last):
File "D:/Fragrance selector/main.py", line 16, in <module>
s = info.get_info('https://www.fragrantica.com/perfume/Christian-Dior/Sauvage-Eau-de-Parfum-48100.html')
File "D:\Fragrance selector\fragrance_info_from_net.py", line 24, in get_info
winter = WebDriverWait(chrome_browser, 10).until(
File "D:\Fragrance selector\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
I am genuinely out of ideas with this problem. I have no more ideas on how to get that width percentage from the ratings. I would really appreciate it if some of you could help me figure this out.
try ... exceptstatement to try yourWebDriverWaitin, so you can handle the exception in your program when it occurs.