Reading the HTML viewed by the user

Viewed 48

Using R I would like to download the HTML generated by the following page:

https://digital.fidelity.com/prgw/digital/research/quote/dashboard/summary?symbol=AAPL

The page source does NOT correspond to the HTML that is seen by the user. When I use R functions like readLines or download.file I get the page source, which is not what I want. I want the HTML seen by the user, which I'd like to read into a character vector.

Can this be done? If so, please provide details.

1 Answers

I have been able to save the content of the webpage in a file with the following code :

library(RSelenium)
url <- "https://digital.fidelity.com/prgw/digital/research/quote/dashboard/summary?symbol=AAPL"
shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox")
remDr$open()
remDr$navigate(url)
Sys.sleep(10)
page_Content <- remDr$getPageSource()[[1]]
writeLines(page_Content, con = "C:\\test.html")

The variable page_Content contains the code of the webpage. Selenium will execute javascript code if the page contains javascript code.

Related