gpt4 book ai didi

python - 我想获取所有图像,但 selenium python 只获取三个图像

转载 作者:行者123 更新时间:2023-12-05 02:28:15 25 4
gpt4 key购买 nike

我正在尝试从 https://crosset.onward.co.jp/coordinate/2828615 下载 10 张试戴图片通过使用 python selenium,但我只有 3 张图像。代码和相关输出如下。

本网站有<div class="swiper-slide"> ,这可能与这个问题有关,但我不知道如何解决这个问题。

site = "https://crosset.onward.co.jp/coordinate/2828615"
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.get(site)

#driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
#sleep(0.5)

name = driver.find_element_by_class_name("c-breadcrumb__head-text").get_attribute("innerText").strip()
images = driver.find_element_by_css_selector(".p-styling-image.p-styling-image__content")
images = images.find_elements_by_css_selector(".p-link-card__image-body--contain.lazyloaded")
print("number of images : ", len(images))
print(images)
for image in images:
src = image.get_attribute("src")
driver.get(src)
img = driver.find_element_by_tag_name('img').screenshot_as_png
number of images : 3 
[<selenium.webdriver.remote.webelement.WebElement (session="c86015b781750f58884130fac60ea02f", element="1dae6ac3-25f7-4d35-a97e-c3b857e70997")>, <selenium.webdriver.remote.webelement.WebElement (session="c86015b781750f58884130fac60ea02f", element="34b598fa-f1aa-4d71-8928-330857f3a11c")>, <selenium.webdriver.remote.webelement.WebElement (session="c86015b781750f58884130fac60ea02f", element="f4d20c56-f209-41c7-ad34-25c5935aed47")>]

最佳答案

尝试使用此代码获取所需的图像

site = "https://crosset.onward.co.jp/coordinate/2828615"
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.get(site)

containers = driver.find_elements_by_css_selector("div.swiper-slide")

images = []

for container in containers:
image = container.find_element(By.TAG_NAME, 'img')
images.append(image.get_attribute('data-src'))

images = set(images) # There are couple duplicates, so this line required to get unique images only
print(len(images))
print(images)

关于python - 我想获取所有图像,但 selenium python 只获取三个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72709890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com