G H
G H

Reputation: 1

Scraping restaurants long/lat data using rvest

I'm currently trying to scrape lat/long data from tripadvisor. i can see the longitude and latitude in the source code of the page but i can't scrape it. this is my code:

        library(rvest) 
    WS <- "https://www.tripadvisor.fr/Restaurant_Review-g187147-d10514254-Reviews-Les_Apotres_de_Pigalle-Paris_Ile_de_France.html"

link <- read_html(WS)

lat <- link %>%  html_node(".mapContainer ") %>% html_attr("data-lat")

when i run this code i have a "NA".

any help would be awesome ! thanks

Upvotes: 0

Views: 553

Answers (1)

Orhan Solak
Orhan Solak

Reputation: 809

You can try to scrape via xpath

For latitude

"substring-after(substring-before(substring-before(substring-after(normalize-space(//script[contains(.,'lat: ')]), '= {'), ', zoom:'), ','), 'lat: ')"

For longtitude

"substring-after(substring-before(substring-after(normalize-space(//script[contains(.,'lat: ')]), '= {'), ', zoom:'), ' lng: ')"

Upvotes: 2

Related Questions