简体   繁体   English

从谷歌地图中抓取城市的经度和纬度

[英]Scraping longitude and latitude of a city from Google Maps

I want to extract Latitude and Longitude for a city from Google Maps.我想从谷歌地图中提取一个城市的纬度和经度。 The flow should go like this流程应该像这样 go

opening google maps URL Search for a city say 'New York'打开谷歌地图 URL 搜索城市说“纽约”

Now I want to fetch the Latitude and Longitude of this city.现在我想获取这个城市的纬度和经度。 Any help would be appreciated.任何帮助,将不胜感激。 Thanx in advance.提前谢谢。

I could do it with context_click in selenium.我可以使用 selenium 中的context_click来完成。

wait = WebDriverWait(driver, 10)
driver.get("https://www.google.com/maps")
wait.until(EC.element_to_be_clickable((By.ID, "searchboxinput"))).send_keys("New York")
wait.until(EC.element_to_be_clickable((By.ID, "searchbox-searchbutton"))).click()
sleep(5)
ActionChains(driver).move_to_element(driver.find_element_by_xpath("//html/body")).context_click().perform()
print(wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "ul[role='menu']>li div div[class*='text']:nth-of-type(1)"))).text)

O/P:输出/输出:

40.69715, -74.25987 40.69715, -74.25987

Don't forget to import these:不要忘记导入这些:

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

After exploring google maps and how a regular person would find the longitude and latitude i noticed the URL has the longitude and latitude within it so i would search for the location then pull the URL using driver.current_url or something like that(not familiar with python) then set it to a variable and use what ever function to trim it down and separate it so you only have the longitude and latitude in 2 separate variables.在探索了谷歌地图以及普通人如何找到经度和纬度之后,我注意到 URL 里面有经度和纬度,所以我会搜索该位置,然后使用driver.current_url或类似的东西拉 URL 或类似的东西(不熟悉 python ) 然后将其设置为一个变量并使用 function 将其修剪并分开,这样您就只有两个单独的变量中的经度和纬度。 sorry this only breaks down the process rather then giving you a straight answer, if you have any other questions I would prefer you ask me here.抱歉,这只会破坏流程,而不是给你一个直接的答案,如果你有任何其他问题,我希望你在这里问我。 https://discord.gg/fjNX5MuTVq https://discord.gg/fjNX5MuTVq

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将经纬度转换为国家或城市? - how to convert from longitude and latitude to country or city? Python Selenium - 从地图上抓取纬度和经度 - Python Selenium - Webscrape Latitude and Longitude from the Maps 如何离线获取经纬度的国家/城市? - How to get country/city from latitude and longitude offline? 从纬度和经度创建名称为 City 的新列 [on hold] - Create new column with name of City from Latitude and Longitude [on hold] 如何从经纬度坐标列表中获取城市、state 和国家? - How to get city, state, and country from a list of latitude and longitude coordinates? "用于从美国城市名称中获取纬度和经度的 Python 模块" - Python module for getting latitude and longitude from the name of a US city Django:如何从Google Maps用户选择的地址获取经度和纬度并保存到数据库 - Django : How to get longitude and latitude from google maps user selected adress and save to database 从谷歌结果中抓取经纬度 - Webscraping latitude longitude from google results 检查纬度和经度的公式在没有Google Maps Api的区域内 - Formula to Check Latitude & Longitude is within Area without Google Maps Api Python pygmaps无法解析经度和纬度以在Google地图上正确定位 - Python pygmaps not resolving latitude and longitude to correct location on google maps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM