1

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]]
Dave2e
  • 22,192
  • 18
  • 42
  • 50
BlueFx
  • 67
  • 5

1 Answers1

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)
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • Wow, super !!! But could you explain to me where the link 'https://seekingalpha.com/symbol/MNHVF/cresscap/fields_ratings?category_id=4&sa_pro=false' is coming from? Thanks – BlueFx Oct 16 '19 at 08:57
  • I re-loaded your url in browser whilst using network tab of dev tools (F12) to monitor web traffic. I then searched that web traffic for a value I expected to see in the table. For example see here: https://stackoverflow.com/a/56279841/6241235 – QHarr Oct 16 '19 at 09:25