0

How do I extract a stock quote from a javascript enabled webpage? The link to the page is: https://www.tsp.gov/InvestmentFunds/FundPerformance/index.html

I'm looking for the first row, the L2030 latest price.

My R code returns a lexical error: invalid char in json text

Here's my R code:

require(rvest)
require(V8)
require(dplyr)
require(readxl)
require(openxlsx)
require(jsonlite)
require(BatchGetSymbols)
require(magrittr)
require(lubridate)


url<-'https://www.tsp.gov/InvestmentFunds/FundPerformance/index.html'
page<-read_html(url)

tsptable1 <- page %>% 
  rvest::html_nodes('body') %>% html_nodes('td.col3') %>% html_text()


TSPquote<-fromJSON(tsptable1)

Any ideas on solving this, and resources to learn more about javascript enabled webpage scraping?

DougC
  • 1
  • 1
  • This might be of interest: https://www.r-bloggers.com/web-scraping-google-sheets-with-rselenium/ – Waldi Jul 21 '20 at 22:12
  • Tangentially, you're using `require` incorrectly: it never stops the following code when the package is not available, which is almost never what is intended. Refs: https://stackoverflow.com/a/51263513 – r2evans Jul 22 '20 at 00:28

0 Answers0