Reputation: 1
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
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