如何使用 rvest 从网页中提取选择性数据?
How can I extract selective data from a webpage using rvest?
我一直在尝试使用来自 Pitchforkhttps://pitchfork.com/reviews/albums/us-girls-heavy-light/ 的 rvest in r 来显示这首歌的评论评分。在这种情况下,它是 8.5。但不知何故我得到这个:
这是我的代码
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
我们可以从div
的class中得到相关信息,即"score-circle"
。
library(rvest)
webpage %>% html_nodes('div.score-circle') %>% html_text() %>% as.numeric()
#[1] 8.5
我一直在尝试使用来自 Pitchforkhttps://pitchfork.com/reviews/albums/us-girls-heavy-light/ 的 rvest in r 来显示这首歌的评论评分。在这种情况下,它是 8.5。但不知何故我得到这个:
这是我的代码
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
我们可以从div
的class中得到相关信息,即"score-circle"
。
library(rvest)
webpage %>% html_nodes('div.score-circle') %>% html_text() %>% as.numeric()
#[1] 8.5