if (FALSE) {
# When we retrieve the raw HTML for this site, it doesn't contain the
# data we're interested in:
static <- read_html("https://www.forbes.com/top-colleges/")
static |> html_element("table")
# Instead, we need to run the site in a real web browser, causing it to
# download a JSON file and then dynamically generate the html:
dynamic <- read_html_live("https://www.forbes.com/top-colleges/")
# You may need to click the cookie consent banner if it appears
dynamic$view()
# Now we can find the table
dynamic |> html_element("table")
# And extract data from it
dynamic |>
html_element("table") |>
html_table()
}
Run the code above in your browser using DataLab