简体   繁体   English

selenium python 为什么我没有得到图像 url?

[英]selenium python why I am not getting image url?

I am trying to get all gallary image url from this page .我正在尝试从此页面获取所有图片 url。 Every product have multiple images.每个产品都有多个图像。 here is my code where I am trying to get image url:这是我试图获取图像 url 的代码:

img = driver.find_elements_by_css_selector('.gem-gallery-thumbs-carousel img')
for i in img:
    y = i.get_attribute('href')
    print(y)

result:     
None
None
None
None
None
None
  1. The image urls in those elements are contained in src attribute, not in href as mentioned in comments.这些元素中的图像 url 包含在src属性中,而不是在评论中提到的href中。
  2. You probably should add wait / delay to make the page loaded before reading the elements contents.您可能应该在阅读元素内容之前添加等待/延迟以使页面加载。
    So, something like this After appropriate wait / delay should work:所以,这样的事情适当的等待/延迟之后应该起作用:
imgs = driver.find_elements_by_css_selector('.gem-gallery-thumbs-carousel img')
for img in imgs:
    url = img.get_attribute('src')
    print(url)

To output the srcs for those you need to.get_attribute() for src到 output 的 src 为那些你需要的 .get_attribute() for src

wait=WebDriverWait(driver, 60)
driver.get('https://ca.morilee.com/product/quinceanera-dresses/vizcaya/iridescent-crystal-beaded-quinceanera-dress/')
imgs=wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".gem-gallery-thumbs-carousel img")))
for img in imgs:
    print(img.get_attribute("src")

Imports:进口:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

Outputs:输出:

https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0259-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0292-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0061-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0083-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0101-scaled-1-280x400.jpg
https://ca.morilee.com/wp-content/uploads/sites/10/2021/11/89331-0196-scaled-1-280x400.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 python flask 中使用 Selenium 时出现 No such element 异常? - Why am I getting a No such element exception using Selenium in python flask? 我不知道为什么,但我在 Image_url 中没有得到任何东西。我正在使用scrapy - I dont know why but I am not getting anything in Image_url.I am using scrapy 我在 selenium python 上收到此错误 - I am getting this error on selenium python 在原始代码 python,selenium 中替换 url 时出现错误,重新 - I am getting error while replacing url in orginal code python,selenium,re 为什么我无法在 python 中使用 selenium 抓取同一网站的多个 URL? - Why am I not able to scrape Multiple URL's of the same website using selenium in python? 为什么即使元素存在于我的循环中,我也会收到 StaleElementReferenceException? (硒蟒) - Why am I getting StaleElementReferenceException even though the element is present in my loop? (Selenium Python) 为什么我收到此错误? selenium.common.exceptions.NoSuchElementException - Why i am getting this error ? selenium.common.exceptions.NoSuchElementException Python为什么会出现未定义的错误? - Python Why am I getting not defined error? 为什么我在 python 中没有收到 chromedriver 异常 - why i am not getting chromedriver exception in python Python-不确定为什么会收到TypError - Python - Unsure why I am getting an TypError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM