I am trying to scrape values from a page such as this: https://www.barchart.com/futures/quotes/CBX22/options/nov-22 in R, currently using rvest
. Specifically, I want the current price and implied volatility. Using the SelectorGadget tool, I was able to find the nodes needed for these values.
Using the following, I was able to get the implied volatility:
library(rvest)
html <- read_html("https://www.barchart.com/futures/quotes/CBX22/options/nov-22")
html_text(html_nodes(html, '.text-medium-up-center strong'))
[1] "43.92%"
However, it seems the current price can't be scraped in the same way since it is a value that updates every few seconds without needing to refresh the page. Using the same process as with the implied volatility, except subbing in the node for price,
html_text(html_nodes(html, '.pricechangerow > .last-change'))
yields
[1] "[[ item.lastPrice ]]" "[[ rootItem.lastPrice ]]"
Is there a way to retrieve whatever the last price happened to be at the time the html is read?