【问题标题】:Code doesn't find any products on website代码在网站上找不到任何产品
【发布时间】:2019-08-16 03:30:03
【问题描述】:

enter image description here我写了一些代码(下面是其中的一部分)来从商店的网站上抓取所有产品,但它没有找到任何产品...我不知道这段代码有什么问题。有人能帮我吗?我添加了 screnn 来显示 html(产品图块代表一些产品框,所以我认为我应该使用这个类来获得必要的信息)

while True:
    # if True:
    try:
        prod = driver.find_elements_by_class_name("product-tile")
        for el in prod:
            name = el.find_element_by_class_name("product-name").text
            price = el.find_element_by_class_name("price-normal").text
            product_list.append(x)
            x = [name, price]
            print(x)

【问题讨论】:

  • 您是否有指向列出产品的网站或页面中的 HTML 的链接?
  • 我在我的问题中添加了屏幕。我
  • 我在您的问题中没有看到链接。

标签: python selenium screen-scraping


【解决方案1】:

试试下面的代码看看是否有帮助。

prod=WebDriverWait(driver, 20).until(expected_conditions.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.product-tile.js-UA-product")))

for el in prod:
  name = el.find_element_by_class_name("product-name").get_attribute("innerHTML")
  price = el.find_element_by_class_name("price-normal").get_attribute("innerHTML")

请使用以下导入。

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

【讨论】:

  • 嗯仍然无法正常工作,嗯也许应该\我更改类“product-tile”,但它包含所有信息及其独特的类(当我尝试在 HTML 中找到“product-tile”时,数量与一个网页上的产品数量相同)
  • 我又添加了一个类名试试。如果不行,检查是否有可用的 iframe?
  • 哪个 iframe?我不明白。
  • Serach iframe 出现在您的 product-tile 元素所在的位置?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多