Scrape html table in R with rvest

small image

First get all the tables on the web page:

library(rvest)

webpage <- read_html("https://en.wikipedia.org/wiki/COVID-19_testing")

tbls <- html_nodes(webpage, "table")

tbls

Then see which table you need and convert it to dataframe, in this case I am getting table 2

tbls_ls <- webpage %>%
  html_nodes("table") %>%
  .[2] %>%
  html_table(fill = TRUE)
  
df <- as.data.frame(tbls_ls)

Updated: