使用R和Chrome抓取网页

时间:2019-10-15 09:14:58

标签: r web-scraping rvest

我正在尝试使用Chrome检查中的路径将此表从此网站拉入R中,但它不起作用。你能帮我吗?谢谢。

library(rvest)
library(XML)

url <- "https://seekingalpha.com/symbol/MNHVF/profitability"
webpage <- read_html(url)
rank_data_html <- html_nodes(webpage, 'section#cresscap') # table.cresscap-table
rank_data <- html_table(rank_data_html)
rank_data1 <- rank_data[[1]]

1 个答案:

答案 0 :(得分:1)

数据来自页面动态执行的其他xhr调用。您可以对此请求并使用jsonlite处理json响应。提取列表的相关列表,并使用dplyr bind_rows生成输出。您可以根据需要重命名列以匹配页面上的列。

library(jsonlite)
library(dplyr)

data <- jsonlite::read_json('https://seekingalpha.com/symbol/MNHVF/cresscap/fields_ratings?category_id=4&sa_pro=false')
df <- bind_rows(data$fields)
head(df)