如何在网站上抓取存储在弹出窗口中的信息地图?



我对网页抓取比较陌生,所以我不确定我应该使用哪种方法来收集特定场景中的信息,其中信息存储在地图上并显示在弹出窗口中,例如:https://utils.ocim.fr/cartocim2/

基本上:

  1. 网站显示地图,
  2. 联系人信息显示在弹出窗口中,
  3. 点击地理标签按钮时将出现一个弹出窗口,
  4. 目标信息是那些存储在弹出窗口
  5. 中的行

我正在考虑使用selenium + xpath方法,但我不确定如何处理:

  1. 有这么多需要点击的按钮

你有什么资源或技巧告诉我从哪里开始吗?

困难重重

这是一个开始,但随着标记开始重叠,它变得有点复杂所以点击元素失败,可能需要添加一个步骤来放大等

from selenium import webdriver
import requests
import pandas as pd
url_base = r'https://utils.ocim.fr/cartocim2/'

driver = webdriver.Chrome(r'C:UsersusernameDownloadschromedriver_win32chromedriver.exe')
driver.get(url_base) #open page
#find all the icons
links = driver.find_elements_by_css_selector('div.leaflet-pane.leaflet-marker-pane > img')

import time
output = [] #temp table to append into
for i in range(5): #chaneg to len(links) when done
links[i].click() #click on first icon
output.append(driver.find_elements_by_xpath('//*[@id="popup-header"]')[0].text) #get the text of the name
time.sleep(1) #sleep
driver.find_element_by_css_selector('#initmap').click() #reset the map - needed as without it the next icon might not be on the screen due to map relocation or popup overlap
time.sleep(1)

最新更新