Skip to content

Commit e345f5f

Browse files
jrosellhadley
andauthored
Improve read_html_live() example (#426)
Fixes #430 --------- Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
1 parent 4618b71 commit e345f5f

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

R/live.R

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@
2727
#' # When we retrieve the raw HTML for this site, it doesn't contain the
2828
#' # data we're interested in:
2929
#' static <- read_html("https://www.forbes.com/top-colleges/")
30-
#' static %>% html_elements(".TopColleges2023_tableRow__BYOSU")
30+
#' static |> html_element("table")
3131
#'
3232
#' # Instead, we need to run the site in a real web browser, causing it to
3333
#' # download a JSON file and then dynamically generate the html:
34-
#'
35-
#' sess <- read_html_live("https://www.forbes.com/top-colleges/")
36-
#' sess$view()
37-
#' rows <- sess %>% html_elements(".TopColleges2023_tableRow__BYOSU")
38-
#' rows %>% html_element(".TopColleges2023_organizationName__J1lEV") %>% html_text()
39-
#' rows %>% html_element(".grant-aid") %>% html_text()
34+
#' dynamic <- read_html_live("https://www.forbes.com/top-colleges/")
35+
#' # You may need to click the cookie consent banner if it appears
36+
#' dynamic$view()
37+
#'
38+
#' # Now we can find the table
39+
#' dynamic |> html_element("table")
40+
#'
41+
#' # And extract data from it
42+
#' dynamic |>
43+
#' html_element("table") |>
44+
#' html_table()
4045
#' }
4146
read_html_live <- function(url) {
4247
check_installed(c("chromote", "R6"))

man/read_html_live.Rd

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)