0

I would like to get the location (coordinates) in latitude and longitude from the clickable map on this web page and other similar pages. I am not sure how to go about this using rvest or a scraping package since the Google Maps link with coordinates as shown below only appears if I click on the Ver Mapa button in blue.

https://www.google.com/maps/embed/v1/search?q=-26.106150272877,-56.89951582606415&key=XXXXXXXXXXXXXX&zoom=14

under <div class="modal-body "id=map-canvas">

Funkeh-Monkeh
  • 649
  • 6
  • 17
  • Shortly after accessing the link and successfully clicking ver mapa, this came up: "Google Maps Platform rejected your request. This IP, site or mobile application is not authorized to use this API key." – dcsuka Sep 09 '22 at 01:06
  • If you click on the ver mapa icon you get a popup that say the location is at 26°06'22.1"S 56°53'58.3"W. I think you might need to use a full-service browser equivalent like RSelenium. I don't think `rvest` functions are going to get you popup data. – IRTFM Sep 09 '22 at 01:21
  • Thanks @IRTFM - any idea how I could use `RSelenium` for this? – Funkeh-Monkeh Sep 09 '22 at 02:49
  • If I were you I would first search SO for “r selenium dialog” and if that fails do further searching on Google and then edit your question to reflect what you found and what you tried. – IRTFM Sep 09 '22 at 06:18
  • Please remove the API key in your code to avoid unauthorized use of it. Tried to remove it but the edit queue is already full. – Nelson Jr. Sep 13 '22 at 07:41

1 Answers1

1

You are right, that the link is executed only when clicking the button. You also cannot access the link through rvest, because it is stored inside of a script. However, the script is loaded together with the HTML. Which means, it is accessible through the source-text of the website.

The website somehow had to know, where the coordinates are, to succesfully query google maps. Since you are only interested in the coordinates (I suppose), here is a code snippet that should get you started. It downloads the html as text and through regex filters the relevant info from the stored google request.

You can play around with the regex here: https://regex101.com/r/XIagYl/1

What I did was just navigate to the source text of the website and ctrl-f "google.com/maps" and there the link was sitting in the script. :)

text <- httr::GET("https://clasipar.paraguay.com/inmuebles/propiedades-rurales/granja-sobre-asfalto-con-infraestructura-completa-2093966") %>% httr::content(as ="text")

stringr::str_extract_all(text,"(?<=q=).*(?=\\&key)")
Datapumpernickel
  • 606
  • 6
  • 14