简体   繁体   中英

Scrape webpage using R and Chrome

I am trying to pull the table from this website into R by using path from Chrome inspection, but it does not work. Could you help me with that? Thanks.

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]]

Data comes from an additional xhr call made dynamically by the page. You can make a request to this and handle json response with jsonlite . Extract the relevant list of lists and use dplyr bind_rows to generate your output. You can rename columns to match those on page if you want.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM