首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >特定元素的WebDriverWait诱导

特定元素的WebDriverWait诱导
EN

Stack Overflow用户
提问于 2020-06-24 17:02:41
回答 1查看 118关注 0票数 1

这个问题是我上一个问题(硒中)的后续问题。我正在从grailed.com (https://www.grailed.com/designers/jordan-brand/hi-top-sneakers)中抓取所有的Air数据。我正在将大小、模型、url和图像url存储在对象中。我目前有一个程序,它可以滚动整个提要并获取所有这些。除了找到图像url外,一切都正常工作。图像URL似乎需要显式的等待,@KunduK建议这样做。我正在尝试实现他的解决方案,以便能够在for循环中提取每个映像:

代码语言:javascript
复制
 while True and len(sneakers) < sneaker_count:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    # Get sneakers currently on page and add to sneakers list
    feed = driver.find_elements_by_class_name('feed-item')
    images = WebDriverWait(driver, 10).until(
      EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".feed-item .listing-cover-photo>img")))
    for item in feed:
      ...

当前,代码会同时获取组中的图像。我试图在“在提要中的项目”块中获取图像。我想要一些类似images = WebDriverWait(driver, 10).until(EC.visibility_of_elements_located((By.SOME SELECTOR", ???)))的东西,但是我真的不知道如何使用'item‘元素来找到这些元素。有人能帮忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-24 19:53:16

要使用python从每个映像中刮取图像url,您必须为visibility_of_all_elements_located()诱导WebDriverWait,您可以使用以下任何一个定位器策略

  • 使用CSS_SELECTOR: 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,driver.get(‘https://www.grailed.com/designers/jordan-brand/hi-top-sneakers'’)打印(my_elem.get_attribute(“href”)用于my_elem in WebDriverWait(驱动程序,a产品卡-容器)
  • 使用XPATH: driver.get('https://www.grailed.com/designers/jordan-brand/hi-top-sneakers')打印([my_elem.get_attribute(“href”)表示my_elem in WebDriverWait(驱动程序,WebDriverWait“//a class=‘product card-my_elem’”)
  • 控制台输出: 'https://www.grailed.com/products/57773-jordan-brand-air-jordan-1-retro-high-og-court-purple','https://www.grailed.com/products/57803-jordan-brand-air-jordan-1-retro-high-og-obsidian','https://www.grailed.com/products/57759-jordan-brand-air-jordan-1-retro-high-og-2017-royal','https://www.grailed.com/products/57760-jordan-brand-air-jordan-1-retro-high-og-2018-shadow','https://www.grailed.com/products/59036-jordan-brand-air-jordan-4-retro-og-2019-bred','https://www.grailed.com/products/115772-jordan-brand-jordan-1-retro-high-og-pine-green','https://www.grailed.com/products/57817-jordan-brand-air-jordan-1-retro-high-og-shattered-backboard-3-0','https://www.grailed.com/products/61668-jordan-brand-travis-scott-travis-scott-x-air-jordan-4-retro-cactus-jack','https://www.grailed.com/products/114979-jordan-brand-air-jordan-1-retro-high-og-unc-to-chi','https://www.grailed.com/products/97122-jordan-brand-air-jordan-1-retro-high-og-fearless','https://www.grailed.com/products/97133-jordan-brand-air-jordan-11-bred-2019','https://www.grailed.com/products/61725-jordan-brand-air-jordan-4-retro-cool-grey','https://www.grailed.com/products/57762-jordan-brand-air-jordan-1-retro-high-og-banned-2016-banned-bred','https://www.grailed.com/products/87098-jordan-brand-travis-scott-travis-scott-x-air-jordan-6-retro-olive','https://www.grailed.com/products/57768-jordan-brand-air-jordan-1-retro-high-og-bred-toe','https://www.grailed.com/products/112831-jordan-brand-air-jordan-1-retro-high-og-royal-toe','https://www.grailed.com/products/111383-jordan-brand-air-jordan-4-retro-black-cat-2020','https://www.grailed.com/products/58136-jordan-brand-travis-scott-travis-scott-x-air-jordan-1-retro-high-og-mocha','https://www.grailed.com/products/57825-jordan-brand-air-jordan-1-retro-high-og-turbo-green','https://www.grailed.com/products/111377-jordan-brand-off-white-air-jordan-5-retro-sp-muslin‘
  • 注意事项:您必须添加以下导入: 从selenium.webdriver.support.ui导入WebDriverWait从selenium.webdriver.common.by导入从selenium.webdriver.support导入expected_conditions作为EC
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62560395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档