/course-materials/application-exercises/ae-09-uoeart-functions/01-individual-pieces.R

https://github.com/rstudio-education/datascience-box · R · 44 lines · 18 code · 15 blank · 11 comment · 0 complexity · 29ba637a2a4de8649890d17bd406e76b MD5 · raw file

  1. # load packages ----------------------------------------------------------------
  2. library(tidyverse)
  3. library(rvest)
  4. # first url --------------------------------------------------------------------
  5. ## set url ----
  6. first_info_url <- "https://collections.ed.ac.uk/art/record/22024?highlight=*:*"
  7. ## read page at url ----
  8. page <- read_html(first_info_url)
  9. ## scrape headers ----
  10. headers <- page %>%
  11. html_nodes("th") %>%
  12. html_text()
  13. ## scrape values ----
  14. values <- page %>%
  15. html_nodes("td") %>%
  16. html_text() %>%
  17. str_squish()
  18. ## put together in a tibble and add link to help keep track ----
  19. tibble(headers, values) %>%
  20. pivot_wider(names_from = headers, values_from = values) %>%
  21. add_column(link = first_info_url)
  22. # second url --------------------------------------------------------------------
  23. ## set url ----
  24. second_info_url <- "___"
  25. ___
  26. # third url --------------------------------------------------------------------
  27. ## set url ----
  28. third_info_url <- "___"
  29. ___