gpt4 book ai didi

python - 无法激活连接到 map 中每个点的框

转载 作者:行者123 更新时间:2023-11-28 17:13:36 25 4
gpt4 key购买 nike

我用 selenium 在 python 中编写了一个脚本,以激活连接到网页 map 上可用的每个点的每个框,但不幸的是我不能用我的脚本来做到这一点。我想不出继续前进的想法。希望有人能指引我走向正确的方向。

到目前为止,这是我尝试过的:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Chrome()
driver.get("https://acwi.gov/monitoring/vm/programs/vm_map.html")
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_all_elements_located((By.TAG_NAME, 'iframe')))
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
for item in driver.find_elements_by_xpath("//g[@id='NWQMC_VM_directory_June2016_3915_0_layer']"):
item.find_element_by_xpath(".//circle[@fill='rgb(237, 81, 81)']").click()

driver.quit()

map 中的元素,下面给出了一个点。它很大,所以我缩减了一个点:

<circle fill="rgb(237, 81, 81)" fill-opacity="1" stroke="rgb(153, 153, 153)" stroke-opacity="1" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="4" cx="478" cy="306" r="4" transform="matrix(1.00000000,0.00000000,0.00000000,1.00000000,0.00000000,0.00000000)" fill-rule="evenodd" stroke-dasharray="none" dojoGfxStrokeStyle="solid"></circle>

一些激活点的图像: image_link

最佳答案

试试这个,它可能需要调整,但它会在一个新的大窗口中打开 map 并缩小,然后单击每个点,以便按顺序逐步通过每个下一个按钮(如果显示)。它打开一个新的大窗口并缩小的原因是为了防止页面重新加载和元素变得陈旧。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep


def recurse():
sleep(3)
elem = driver.find_element_by_css_selector(".titleButton.next")
if elem.is_displayed():
elem.click()
sleep(3)
scrape()
recurse()


def scrape():
pass


driver = webdriver.Chrome()
driver.set_window_size(1615, 924) # Make the window size as large as possible to prevent re-rendering and stale elements.
driver.get("https://acwi.gov/monitoring/vm/programs/vm_map.html")
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_all_elements_located((By.TAG_NAME, 'iframe')))
driver.get(driver.find_element_by_tag_name("iframe").get_attribute("src")) # Get a full window to prevent re-rendering and stale elements.
sleep(15) # Wait for re-rendering to prevent stale elements.

zoom = driver.find_element_by_xpath("//*[@id='mapDiv_zoom_slider']/div[2]")
zoom.click() # Zoom out to prevent re-rendering and stale elements.
for item in driver.find_elements_by_tag_name('circle'):
ActionChains(driver).move_to_element(item).click().perform()
scrape()
recurse()
sleep(3)

driver.quit()

关于python - 无法激活连接到 map 中每个点的框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45655421/

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