Class activity solutions

Author

Ciaran Evans

library(rvest)
library(tidyverse)
read_html("https://taskmaster.fandom.com/wiki/Series_15") |>
  html_element("[data-source^='champion'] > .pi-font") |>
  html_text2()
[1] "Mae Martin"
urls <- paste0("https://taskmaster.fandom.com/wiki/Series_", 1:15)
champions <- rep(NA, 15)
for(i in 1:15){
  champions[i] <- read_html(urls[i]) |>
  html_element("[data-source^='champion'] > .pi-font") |>
  html_text2()
}
champions
 [1] "Josh Widdicombe"  "Katherine Ryan"   "Rob Beckett"      "Noel Fielding"   
 [5] "Bob Mortimer"     "Liza Tarbuck"     "Kerry Godliman"   "Lou Sanders"     
 [9] "Ed Gamble"        "Richard Herring"  "Sarah Kendall"    "Morgana Robinson"
[13] "Sophie Duker"     "Dara Ó Briain"    "Mae Martin"      
  1. One option:
read_html("https://thehornesection.com/shows/") |>
  html_element("td.gigpress-date") |>
  html_text2()
[1] "17/12/23"

Another option:

read_html("https://thehornesection.com/shows/") |>
  html_element("table") |>
  html_table()
# A tibble: 1 × 6
  Date     City   Venue            ``                                ``    ``   
  <chr>    <chr>  <chr>            <chr>                             <chr> <chr>
1 17/12/23 London indigo at the O2 "Time: 7:30pm.\n\t\t\t\t\t\t\n\t… "Tim… "Add…
read_html("https://taskmaster.fandom.com/wiki/Alex_Horne") |>
  html_element("[data-source^='twitter']") |>
  html_element("a") |>
  html_attr("href")
[1] "https://twitter.com/AlexHorne"