该页面最初仅加载1个图像。
要获得更多图像,必须滚动页面。
因此,无需滚动页面,即可使用
images = driver.find_elements_by_css_selector('#shopify-section-product-template .Image--lazyLoaded')
中只有一个元素
images
列表
UPD
您可以单击左侧的dot导航,然后获得图像:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".Product__SlideshowNavScroller")))
time.sleep(0.2)
dots = driver.find_elements_by_css_selector('.Product__SlideshowNavScroller a')
image_src = set()
for dot in dots:
dot.click()
time.sleep(1)
images = driver.find_elements_by_css_selector('#shopify-section-product-template .Image--lazyLoaded')
for image in images:
image_src.add(image.get_attribute('data-original-src'))
image_src
最终将包含所有图片src链接