python - 我可以使用 selenium.webdriver.Chrome 从 ASDA 网站提取产品信息吗?
问题描述
我正在尝试在 Python 中使用 selenium.webdriver.chrome 从 groceries.asda.com 中提取产品信息
但是,如果我转到特定页面(https://groceries.asda.com/shelf/everyday-family-cereals/2-for-4-cereals/_/3097456947)并在 Google Chrome 中查看其源代码,我可以'找不到产品名称,所以我无法使用 find_element_by_xpath 等方法
有谁知道如何使用 selenium 从 ASDA 网站上提取产品名称?
试过xpath、css选择器,都返回NoSuchElementException
from selenium import webdriver
url = "https://groceries.asda.com/shelf/everyday-family-cereals/2-for-4-cereals/_/3097456947"
driver = webdriver.Chrome()
driver.get(url)
nav = driver.find_element_by_xpath('//*[@id="listingsContainer-0bd93fc4-888f-52c5-1c47-5679e4aab507"]/div/div[1]/div[2]/div/div/div[2]/span[1]/a/span')
product = nav.text
print(product)
NoSuchElementException
解决方案
尝试这种方法 - 这应该使用其“alt”属性打印所有产品详细信息
Products = driver.find_elements_by_xpath("//div[@class=' co-product-list']//a/img")
print(len(Products))
for product in Products:
print(product.get_attribute('alt'))
推荐阅读
- reactjs - react16 的日期选择器库
- java - 无法实例化 Kafka 结构化流 KafkaSourceProvider
- date - 如何从日期选择器中添加 JMeter 中的日期?
- azure-data-factory - Azure 数据工厂中的 WaitActivity 我们如何从过滤器活动中传递参数值
- .net-core - .HttpContext.Features.Get
().ReasonPhrase 在 .net core 2.1 中不起作用? - dart - 如何在执行 POST 请求时解决颤振 CERTIFICATE_VERIFY_FAILED 错误?
- node.js - 结合 readline 和 puppeteer 时,console.log 中的进程被阻止
- python - 无法将 excel 行与 pandas 数据框行数匹配
- java - Java 中的 Google Indexing API 请求批处理
- azure - Azure Net core:指定的 CGI 应用程序遇到错误,服务器终止了进程