Sunday, 30 July 2023

R/Python: Extracting Information from Google Maps

I am working with the R and Python languages.

Suppose I search for the following Canadian Postal Code (M5V 3L9) on Google Maps:

https://www.google.com/maps/place/Toronto,+ON+M5V+3L9/@43.642566,-79.3875851,18z/data=!4m6!3m5!1s0x882b34d436f9c825:0x9e9c6195e38030f2!8m2!3d43.6429129!4d-79.3853443!16s%2Fg%2F1tvq4rqd?entry=ttu

When I search for this, I can see that the "perimeter" of this Postal Code is highlighted in red:

enter image description here

My Question: (Using Selenium via R/Python) From an HTML/CSS/XML perspective - I am trying to get a list of all coordinates that make up the boundary of this perimeter.

I have been trying to explore the source code that is generated from this website to try and see if there is something I can do to see where the source code of this perimeter (e.g. in JSON) is being stored - but so far, I can't find anything:

enter image description here

I was hoping that perhaps there might be something which would allow me to use Selenium to repeatedly click around this perimeter and extract the longitude/latitude points - but so far, I can not find anything.

Can someone please show me how to do this?

Thanks!

Note: Generic Selenium Code:

library(RSelenium)
library(wdman)
library(netstat)

selenium()
seleium_object <- selenium(retcommand = T, check = F)

remote_driver <- rsDriver(browser = "chrome", chromever = "114.0.5735.90", verbose = F, port = free_port())

remDr<- remote_driver$client


remDr$navigate("https://www.google.com/maps/place/Toronto,+ON+M5V+3L9/@43.642566,-79.3875851,18z/data=!4m6!3m5!1s0x882b34d436f9c825:0x9e9c6195e38030f2!8m2!3d43.6429129!4d-79.3853443!16s%2Fg%2F1tvq4rqd?entry=ttu")   

element <- remDr$findElement(using = "class", value = "leaflet-popup-content")
content <- element$getElementText()[[1]]


from R/Python: Extracting Information from Google Maps

No comments:

Post a Comment