Ishaan Bedi
Ishaan Bedi

Reputation: 51

How can I extract selective data from a webpage using rvest?

I have been trying to display the review rating of this song using rvest in r from Pitchforkhttps://pitchfork.com/reviews/albums/us-girls-heavy-light/ . In this case, it is 8.5. But somehow I get this: enter image description here

Here is my code

library(rvest)
library(dplyr)
library(RCurl)
library(tidyverse)

URL="https://pitchfork.com/reviews/albums/us-girls-heavy-light/"

webpage = read_html(URL)


cat("Review Rating")
webpage%>%
   html_nodes("div span")%>%
   html_text

Upvotes: 1

Views: 61

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389355

We can get the relevant information from the class of div which is "score-circle".

library(rvest)

webpage %>% html_nodes('div.score-circle') %>% html_text() %>% as.numeric()
#[1] 8.5

Upvotes: 5

Related Questions