Мой код должен загрузить веб-сайт, дождаться появления динамически заполняемых элементов определенного класса и получить атрибут классов.
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
driver = webdriver.Edge(executable_path=r'path\to\MicrosoftWebDriver.exe')
driver.get('https://website')
result="placeholder"
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "class name"))
)
finally:
html_input = driver.page_source
soup = BeautifulSoup(html_input, features="html.parser")
for each_item in soup.findAll(class_='class name'):
result = each_item['href']
print(result)
driver.quit()
Код: Выделить всё
*The output I was looking for*
Traceback (most recent call last):
File "code.py", line 47, in
element = WebDriverWait(driver, 10).until(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\username\anaconda3\envs\CondaEnv\Lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Подробнее здесь: https://stackoverflow.com/questions/787 ... ndition-is