如何解决将鼠标悬停在画布元素Python / Selenium上,即可生成网络抓取弹出式信息
我试图保存将鼠标悬停在此地图中的每个人口普查区上时显示的弹出框中显示的信息:https://childcaredeserts.org/2018/index.html?state=WA 到目前为止,我最好的策略就是尝试通过单击地图的不同坐标来获取信息,但是我的点击超出了限制,这会遇到一些问题。当然,这种方法并不是最有效的,但是我担心由于地图是画布元素,因此无法实现自动化。
是否可以针对地图中的所有普查轨迹自动提取此信息?如何以更有效的方式获取此信息?
如果有什么帮助,这是我的实际代码(可以运行,但不足以满足我的需要):
import time
import csv
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://fuelinsights.gasbuddy.com/Charts');
driver.get('https://childcaredeserts.org/2018/index.html?state=WA')
action = ActionChains(driver);
time.sleep(20)
canvas = driver.find_element_by_css_selector("canvas.mapboxgl-canvas")
location = canvas.location
size = canvas.size
print(location)
print(size)
action.move_to_element(canvas).click().perform()
res= []
start= 0
stop= 10
step= 1
action.move_by_offset(-50,-50).click().perform()
for x in range(start,stop,step):
action.move_by_offset(x,0).click().perform()
print(x)
box=driver.find_element_by_xpath('//*[@id="root"]/div/div[2]')
res.append(box.text.replace('\n',' '))
print(res)
任何指导将不胜感激。 谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。