【问题标题】:Python Selenium unable to get alt src attributePython Selenium 无法获取 alt src 属性
【发布时间】:2021-06-02 16:00:21
【问题描述】:

我无法访问所有产品的 img src。对于某些元素,图像 src 属性值返回“无”。我注意到图像元素有时没有指定 alt,因此该元素可能如下所示:

这似乎在解析 src 属性时产生了问题。有解决办法吗?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

webdriver.DesiredCapabilities.CHROME['acceptSslCerts']=True

# Routing if using Chrome driver
driver = webdriver.Chrome()

categories = [
    "sleeping+bags",
    "sleeping+pads",
    "carabiners"
]

for category in categories:
    
  driver.get(f'https://www.backcountry.com/Store/catalog/search.jsp?s=u&q={category}')

  def get_products():
      products = driver.find_elements_by_class_name('product')
      for product in products:
          brand = product.find_element_by_class_name('ui-pl-name-brand').text
          model = product.find_element_by_class_name('ui-pl-name-title').text
          image = product.find_element_by_class_name('ui-pl-img').find_element_by_tag_name('img').get_attribute('src')

          print({ "category": category, "page": page, "brand": brand, "model": model, "image": image})

  # BEGIN EXECUTION:

  page = 1

  get_products()

  loop = True
  while loop:
      try:
          next_page = driver.find_element_by_link_text('Next Page')
          next_page.click()

          time.sleep(3)
          page += 1

          get_products()
      except:
          loop = False

【问题讨论】:

  • 您是否遇到任何错误?还是有什么问题?
  • 图像值返回为“无”
  • 例如:{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 20F Down', 'image': None, 'price': '188.95'} 'image' 应该返回一个 url:{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': "Lamina Sleeping Bag: 30F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9GH/NORBLU.jpg', 'price': '179.95'}

标签: python selenium selenium-webdriver web-scraping


【解决方案1】:

您的问题是,当您尝试获取 src 属性时,图像未加载,因此它确实是空的。您可以通过在抓取src 之前诱导WebDriverWait 使元素可见来解决此问题。这是我使用的代码:

image = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.ui-pl-img img'))).get_attribute('src')

您需要添加导入:

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

所以你的整个代码可能如下所示:

from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

webdriver.DesiredCapabilities.CHROME['acceptSslCerts']=True

# Routing if using Chrome driver
driver = webdriver.Chrome()

categories = [
    "sleeping+bags",
    "sleeping+pads",
    "carabiners"
]
wait = WebDriverWait(driver, 10)
for category in categories:

  driver.get(f'https://www.backcountry.com/Store/catalog/search.jsp?s=u&q={category}')

  def get_products():
      products = driver.find_elements_by_class_name('product')
      for product in products:
          brand = product.find_element_by_class_name('ui-pl-name-brand').text
          model = product.find_element_by_class_name('ui-pl-name-title').text
          image = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.ui-pl-img img'))).get_attribute('src')

          print({ "category": category, "page": page, "brand": brand, "model": model, "image": image})

  # BEGIN EXECUTION:

  page = 1

  get_products()

  loop = True
  while loop:
      try:
          next_page = driver.find_element_by_link_text('Next Page')
          next_page.click()

          time.sleep(3)
          page += 1

          get_products()
      except:
          loop = False

我得到这样的输出:

{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': "Cat'S Meow Sleeping Bag: 20F Synthetic", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Wasatch Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Coleman', 'model': 'Kompact Sleeping Bag: 40 Degree Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': 'Trestles 15 Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Dolomite One Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Rab', 'model': "Solar 3 Synthetic Sleeping Bag - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Kelty', 'model': "Cosmic 20 Sleeping Bag: 20F Down - Men'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': "Trestles 15 Sleeping Bag: 15F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': "Lamina Sleeping Bag: 30F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': 'Lamina Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 20F Down', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': "Lamina Sleeping Bag: 0F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': "Trestles 30 Sleeping Bag: 30F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Coleman', 'model': 'Kompact Sleeping Bag: 25 Degree Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Wasatch Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': 'NanoWave 25 Sleeping Bag: 25F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'ALPS Mountaineering', 'model': 'Blue Springs Sleeping Bag: 35F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Kelty', 'model': "Mistral Sleeping Bag: 20F Synthetic - Kids'", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': 'Lamina Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': 'Trestles 0 Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': 'Lamina Eco AF Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'ALPS Mountaineering', 'model': 'Double Wide Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'ALPS Mountaineering', 'model': 'Crescent Lake Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'NEMO Equipment Inc.', 'model': "Tempo 20 Sleeping Bag: 20F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': 'Bozeman 15 Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': "Lamina Sleeping Bag: 15F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': 'Never Summer Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Stoic', 'model': 'Groundwork Single Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Rab', 'model': 'Solar 4 Synthetic Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': 'Lamina Sleeping Bag: -20 Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'NEMO Equipment Inc.', 'model': 'Jazz Duo Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Kelty', 'model': "Callisto 30 Sleeping Bag: 30F Synthetic - Kids'", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Kelty', 'model': 'Cosmic Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Kelty', 'model': "Mistral Sleeping Bag: 30F Synthetic - Kids'", 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': 'Trestles 30 Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'ALPS Mountaineering', 'model': 'Crescent Lake Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Marmot', 'model': 'NanoWave 55 Sleeping Bag: 55F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Mountain Hardwear', 'model': 'Bozeman 0 Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 1, 'brand': 'Big Agnes', 'model': 'Lost Dog Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/TNF/TNF03ZE/BLWITEGR.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': 'Lamina Eco AF Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': 'Rook Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Blue Kazoo Sleeping Bag: 15F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Kelty', 'model': "Cosmic 20 Sleeping Bag: 20F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Kelty', 'model': "Cosmic 20 Sleeping Bag: 20F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Big Agnes', 'model': "Sidewinder SL Sleeping Bag: 35F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Therm-a-Rest', 'model': 'Saros Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Gold Kazoo Down Sleeping Bag: 35F', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 55F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': 'Ultra Elite 30 Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': "Rook Sleeping Bag: 0F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Rab', 'model': "Solar 2 Synthetic Sleeping Bag - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'NEMO Equipment Inc.', 'model': 'Sonic -20 Sleeping Bag: -20F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': 'NanoWave 45 Sleeping Bag: 45F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': 'Ultra Elite 20 Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': 'Phantom GORE-TEX Sleeping Bag: -40F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Big Agnes', 'model': 'Lost Dog Sleeping Bag: 45F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Rab', 'model': 'Neutrino 800 Sleeping Bag: -5F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Therm-a-Rest', 'model': 'Saros Sleeping Bag: 32F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Kelty', 'model': 'Cosmic Sleeping Bag: 40F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Eco Trail Sleeping Bag: 35F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': "Bishop Pass Sleeping Bag: 0F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Big Agnes', 'model': 'Lost Dog Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Kelty', 'model': "Tuck Sleeping Bag: 20F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Inferno Sleeping Bag: -20F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'ALPS Mountaineering', 'model': 'Razor Fleece Sleeping Bag/Liner', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': 'Trestles Elite Eco 0 Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Big Agnes', 'model': 'Lost Dog Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': "Bozeman Sleeping Bag: 15F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': "Bozeman Sleeping Bag: 30F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': 'Warmcube Expedition Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Therm-a-Rest', 'model': 'Parsec Sleeping Bag: 20F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': 'Micron 40 Sleeping Bag: 40F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': "Banzai Trestles 35 Sleeping Bag: 35F Synthetic - Kids'", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Sea To Summit', 'model': '100% Premium Silk Sleeping Bag Liner', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Inferno Sleeping Bag: -40F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'ALPS Mountaineering', 'model': 'Cosmic Quilt', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Marmot', 'model': "Teton Sleeping Bag: 15F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Rab', 'model': 'Solar 2 Synthetic Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountainsmith', 'model': 'Redcloud Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'The North Face', 'model': 'Green Kazoo Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 2, 'brand': 'Mountain Hardwear', 'model': "Rook Sleeping Bag: 15F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHWZ9G9/UND.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': 'Yolla Bolly Doublewide 30 Sleeping Bag: 30 Degree Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': "Rook Sleeping Bag: 15F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Western Mountaineering', 'model': 'UltraLite Sleeping Bag: 20F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'The North Face', 'model': 'The One Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': 'Buell Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': 'Rook Sleeping Bag: 30F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': "Trestles 30 Sleeping Bag: 30F Synthetic - Kids'", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': "Forte 20 Sleeping Bag: 20F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': 'Micron 50 Sleeping Bag: 50F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': 'Never Winter Sleeping Bag: 30F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': 'Lamina Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Morrison Outdoors', 'model': "Big Mo 20 Sleeping Bag - Toddlers'", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': 'Cabin Creek Double Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': 'Husted Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': 'Anvil Horn Sleeping Bag: 15F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Kelty', 'model': 'Cosmic 0 Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': 'Lamina Eco AF Sleeping Bag: 15F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Rab', 'model': 'Solar 1 Synthetic Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': "Riff 30 Sleeping Bag: 30-Degree Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': 'Sleepy Bear 35 FireLine Core Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Sea To Summit', 'model': "Altitude AtI Sleeping Bag: 25F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': "Sunbeam Sleeping Bag: 0F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': "Angel Fire Sleeping Bag: 25F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Sea To Summit', 'model': 'Ember EbI Sleeping Bag: 40F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': 'Phantom Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Big Agnes', 'model': "Blue Lake Sleeping Bag: 25F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Rab', 'model': "Andes 800 Sleeping Bag: -8F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': "Azura 35 Sleeping Bag: 35F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': 'Tempo 35 Sleeping Bag: 35F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Rab', 'model': 'Ascent 500 Sleeping Bag: 24F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': 'Forte 20 Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': 'Bishop Pass Sleeping Bag: 15F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Klymit', 'model': 'Nest Sleeping Bag Liner', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Rab', 'model': 'Solar 3 Synthetic Sleeping Bag', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': "Tempo 35 Sleeping Bag: 35F Synthetic - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Western Mountaineering', 'model': 'Versalite Sleeping Bag: 10F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'NEMO Equipment Inc.', 'model': 'Tempo 20 Sleeping Bag: 20F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Mountain Hardwear', 'model': 'Bozeman 30 Sleeping Bag: 30F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': 'Sawtooth Sleeping Bag: 15F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Western Mountaineering', 'model': 'Everlite Sleeping Bag: 45F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Rab', 'model': "Ascent 700 Sleeping Bag: 17F Down - Women'S", 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 3, 'brand': 'Marmot', 'model': 'Helium Sleeping Bag: 15F Down', 'image': 'https://content.backcountry.com/images/items/medium/MAR/MARZ9I7/BOGAKEGR.jpg'}
{'category': 'sleeping+bags', 'page': 4, 'brand': 'Mountain Hardwear', 'model': 'Phantom GORE-TEX Sleeping Bag: 0F Down', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHW01CT/ALPRD.jpg'}
{'category': 'sleeping+bags', 'page': 4, 'brand': 'Mountainsmith', 'model': 'Crestone Sleeping Bag: 0F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHW01CT/ALPRD.jpg'}
{'category': 'sleeping+bags', 'page': 4, 'brand': 'Big Agnes', 'model': "Wolverine Sleeping Bag: 15F Synthetic - Kids'", 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHW01CT/ALPRD.jpg'}
{'category': 'sleeping+bags', 'page': 4, 'brand': 'Big Agnes', 'model': 'V Notch UL Sleeping Bag: 40F Synthetic', 'image': 'https://content.backcountry.com/images/items/medium/MHW/MHW01CT/ALPRD.jpg'}
.....

【讨论】:

  • 你是个摇滚明星!谢谢。此解决方案根据需要起作用。
  • 是否有特定原因 time.sleep(10) 不能以同样的方式解决问题,@C。啄?
  • 确实如此,但它会让你的脚本永远存在。来自 selenium 的动态等待将等待该元素的可见性所需的时间。
【解决方案2】:

看看这是否有效


productResults  = driver.find_elements_by_xpath(".//div[contains(@class,'product-grid')]/div[@aria-label='Product']")
for e in productResults:
    print(e.find_element_by_xpath(".//div[contains(@class,'img')]/img").get_attribute("src"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多