【问题标题】:Cannot find elements when scraping website with python and selenium使用 python 和 selenium 抓取网站时找不到元素
【发布时间】:2021-03-14 18:24:27
【问题描述】:

我想将颜色 HSB 值映射到英文颜色名称和色调名称。我发现的一个资源是 https://www.color-blindness.com/color-name-hue/ 我正在使用 Selenium 来抓取它。 似乎我找不到我感兴趣的元素。 这是我的尝试:

import selenium
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.color-blindness.com/color-name-hue/')

driver.implicitly_wait(60)

driver.find_element_by_css_selector("input#cp1_Hue")

其他一些尝试:

driver.find_element_by_id("cp1_Hue")

我不断收到此错误消息: NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input#cp1_Hue"} (Session info: chrome=89.0.4389.82)

有人遇到过同样的问题吗?

提前致谢!

【问题讨论】:

  • 解决方法已经写在下面了
  • 尝试this link 从帖子中的链接中抓取您想要的任何内容。好消息是您可以在请求模块中使用此链接,因为此处提供的内容是静态的。

标签: python selenium web-scraping


【解决方案1】:

有Iframe元素,里面的元素是不允许交互的。

  1. 你应该打开它
  2. 与您正在寻找的元素进行交互

试试这个:

driver = webdriver.Chrome()
driver.get('https://www.color-blindness.com/color-name-hue/')

driver.implicitly_wait(5)

driver.switch_to.frame(driver.find_element(By.TAG_NAME, 'iframe'))

input = driver.find_element(By.CSS_SELECTOR, "input#cp1_Hue")
input.send_keys(10)

driver.quit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    • 2020-03-24
    • 2023-04-01
    相关资源
    最近更新 更多