简体   繁体   English

使用 python 和 selenium 抓取网站时找不到元素

[英]Cannot find elements when scraping website with python and selenium

I would like to map color HSB values to English color names and Hue names.我想将 map 颜色 HSB 值改为英文颜色名称和色调名称。 One resource I have found is https://www.color-blindness.com/color-name-hue/ and I am using Selenium to scrape it.我发现的一个资源是https://www.color-blindness.com/color-name-hue/我正在使用 Selenium 来刮它。 It seems though that I cannot find the elements I am interested in. This is my attemp:似乎我找不到我感兴趣的元素。这是我的尝试:

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")

Some other attempts:其他一些尝试:

driver.find_element_by_id("cp1_Hue")

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

Has anyone faced the same issue?有没有人遇到过同样的问题?

Thanks in advance!提前致谢!

There's Iframe element, what doesn't allow to interact with elements inside it.有 Iframe 元素,不允许与其中的元素交互。

  1. You should switch on it你应该打开它
  2. Interact with elements what you're looking for与您正在寻找的元素进行交互

try this:尝试这个:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM