gpt4 book ai didi

python - 为什么鼠标悬停数据消失

转载 作者:行者123 更新时间:2023-11-28 18:00:23 26 4
gpt4 key购买 nike

当我将鼠标悬停在元素上时,它会以 HTML 代码显示表格但是当我滚动时,广告再次尝试悬停,它不起作用?任何帮助

from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(0)
url = 'https://public.tableau.com/views/IRENA_Decentralised_RE_Data_Review_2019/ExploreData?:showVizHome=no'
driver.get(url)
time.sleep(3)

for i in range(10000):
element = driver.find_element_by_xpath("//div[@class='tab-tvScrollY tvimages'][./div[@class='tvimagesContainer' and @style]]")
driver.execute_script('arguments[0].scrollTop = (0,{})'.format(str(i*49)),element)
actions = ActionChains(driver)
actions.move_by_offset(1330,200).perform()
time.sleep(3)

最佳答案

花了三个小时,终于搞定了!

悬停 的某些 Tableau 行为也不起作用,无法说明原因。

下面是我的代码,解释了我为悬停所有行所做的工作。

import time

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome(executable_path='./chromedriver')
driver.maximize_window()
driver.implicitly_wait(0)
url = 'https://public.tableau.com/views/IRENA_Decentralised_RE_Data_Review_2019/ExploreData?:showVizHome=no'
driver.get(url)
time.sleep(2)

scroll = driver.find_element_by_xpath("//div[@class='tab-tvScrollY tvimages']"
"[./div[@class='tvimagesContainer' and @style]]")
column = driver.find_elements_by_xpath("//canvas[@class='tabCanvas tab-widget']")[1]

action = ActionChains(driver)
for i in range(10000):
driver.execute_script('arguments[0].scrollTop = (0,%s)' % str(i * 49), scroll)

# Move cursor to hover element
action.move_to_element_with_offset(column, 0, 0).perform()

# Select HTML table
table = driver.find_element_by_xpath("//div[@class='tab-tooltip tab-widget "
"tab-tooltipBL tab-allowMouseEventPassthrough']")
# Your selenium code to extract HTML content [...]

# Move cursor to reset tableau hover function behavior
action.move_to_element(scroll).perform()

希望对您有所帮助!

关于python - 为什么鼠标悬停数据消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56072366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com