from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
driver.get("https://audible.com/search")
data_containers = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '[data-widget*=product] .productListItem')))
for container in data_containers:
title = container.find_element(By.CLASS_NAME, 'bc-heading').get_property('innerText')
author = container.find_element(By.CLASS_NAME, 'authorLabel').get_property('innerText')
duration = container.find_element(By.CLASS_NAME, 'runtimeLabel').get_property('innerText')
# and append them to your dictionary
1条答案
按热度按时间ifsvaxew1#
您遇到的问题可能与网站渲染有关。
你不需要等待容器元素存在,所以它可以在空列表中循环。
要等待渲染,您可以将
presence_of_all_elements_located
与WebDriverWait
一起使用。