【发布时间】:2020-10-22 03:06:00
【问题描述】:
我需要来自https://childcaredeserts.org/2018/index.html?state=ID 的信息,特别是当我将鼠标悬停在某个状态时弹出的信息。我尝试过使用 selenium 和 python(我是网络抓取的新手),但我不知道如何获取地图的信息,地图似乎是一个画布元素(在 HTML5 中使用过调查) ,所以我对如何做到这一点有点困惑。
欢迎任何帮助。如有必要,我愿意使用其他编程语言。 也许我不太了解我正在努力解决的画布元素。
到目前为止我的代码:
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600')
driver = webdriver.Chrome('../Downloads/chromedriver', options=options)
driver.get('https://childcaredeserts.org/2018/index.html?state=WA');
action = ActionChains(driver);
time.sleep(20)
element = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CLASS_NAME, "f1sovyv3")))
#here is where I define the path of info, not sure if it's ok
test = driver.find_elements_by_xpath("//*[name()='div' and @id='root']/*[name()='div']")
res = []
for el in test:
hover = action.move_to_element(el)
hover.perform()
#Below here is supposed to receive the info and append it to a list called res
#licensed_child_care_providers
#family_child_care_homes
#state
#res.append((licensed_child_care_providers, family_child_care_homes, state)))
for i in res:
print(i)
driver.quit()
【问题讨论】:
标签: python selenium selenium-webdriver web-scraping html5-canvas