Question 2 - View Source and Inspect

url <- "https://en.wikipedia.org/wiki/2026_in_film"

page <- read_html(url)

page
## {html_document}
## <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-menu-disabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 skin-theme-clientpref-day vector-sticky-header-enabled vector-toc-available skin-thumbsize-clientpref-standard skin-underline-clientpref-browser" lang="en" dir="ltr">
## [1] <head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8 ...
## [2] <body class="mediawiki ltr sitedir-ltr mw-hide-empty-elt action-view skin ...

Question 3 - CSS Selector Approach

tables <- page %>%
  html_elements("table.wikitable")

length(tables)
## [1] 5

Question 4 - HTML Table Function

all_tables <- tables %>%
  lapply(html_table, fill = TRUE)

length(all_tables)
## [1] 5

Question 5 - Robots.txt

paths_allowed(
  "https://en.wikipedia.org/wiki/2026_in_film"
)
##  en.wikipedia.org
## [1] TRUE

#Question 6 - Highest-Grossing Films 2026

url <- "https://en.wikipedia.org/wiki/2026_in_film"

page <- read_html(url)

tables <- page %>%
  html_elements("table.wikitable") %>%
  lapply(html_table, fill = TRUE)

matches <- Filter(function(x) {
  all(c("Rank", "Title", "Worldwide gross") %in% names(x))
}, tables)

hg_2026 <- matches[[1]]

knitr::kable(hg_2026)
Rank Title Distributor Worldwide gross
1 Spider-Man: Brand New Day † Sony $2,521,214,671
2 The Odyssey Universal $1,801,737,440
3 Toy Story 5 Disney $1,149,397,987
4 Michael Lionsgate / Universal $1,028,703,388
5 The Super Mario Galaxy Movie Universal $1,013,2447,550
6 The Devil Wears Prada 2 20th Century $693,492,689
7 Project Hail Mary Amazon MGM / Sony $684,639,091
8 Pegasus 3 Maoyan $656,459,523
9 Minions & Monsters Universal $529,902,727
10 Obsession Focus / Universal $524,331,713

Question 8 - Bonus: Highest-Grossing Films 2020-2025

hg_films <- data.frame()

for (year in 2020:2025) {

  url <- paste0(
    "https://en.wikipedia.org/wiki/",
    year, "_in_film"
  )

  page <- read_html(url)

  tables <- page %>%
    html_elements("table.wikitable") %>%
    lapply(html_table, fill = TRUE)

  matches <- Filter(function(x) {
    all(c("Rank", "Title", "Worldwide gross") %in% names(x))
  }, tables)

  films <- matches[[1]]

  films$Year <- year

  hg_films <- bind_rows(hg_films, films)

  Sys.sleep(1)
}

print(table(hg_films$Year))
## 
## 2020 2021 2022 2023 2024 2025 
##   10   10   10   10   10   10
knitr::kable(hg_films)
Rank Title Distributor Worldwide gross Year
1 Demon Slayer: Kimetsu no Yaiba Mugen Train Toho / Aniplex $507,127,293[4] 2020
2 The Eight Hundred CMC Pictures $461,421,559 2020
3 My People, My Homeland China Lion $433,241,288[5] 2020
4 Bad Boys for Life Sony $426,505,244 2020
5 Tenet Warner Bros. $365,309,519 2020
6 Sonic the Hedgehog Paramount $319,715,683 2020
7 Dolittle Universal $251,410,631 2020
8 Jiang Ziya Beijing Enlight $243,883,429 2020
9 A Little Red Flower HG Entertainment $238,600,000[6][7] 2020
10 Shock Wave 2 Universe Films $226,400,000 2020
1 Spider-Man: No Way Home Sony $1,921,426,073[nb 1] 2021
2 The Battle at Lake Changjin Bona $909,596,236 2021
3 Hi, Mom Lian Ray $841,674,419 2021
4 No Time to Die MGM / Universal $774,253,007 2021
5 F9 Universal $726,229,501 2021
6 Detective Chinatown 3 Warner Bros. / Wanda $686,257,563 2021
7 Venom: Let There Be Carnage Sony $506,863,592 2021
8 Godzilla vs. Kong Warner Bros. / Toho $470,116,094 2021
9 Shang-Chi and the Legend of the Ten Rings Disney $432,243,292 2021
10 Dune Warner Bros. $411,000,000 2021
1 Avatar: The Way of Water 20th Century $2,320,250,281[nb 1] 2022
2 Top Gun: Maverick Paramount $1,495,696,292[nb 1] 2022
3 Jurassic World Dominion Universal $1,001,978,080 2022
4 Doctor Strange in the Multiverse of Madness Disney $955,775,804 2022
5 Minions: The Rise of Gru Universal $940,628,210 2022
6 Black Panther: Wakanda Forever Disney $859,208,836 2022
7 The Batman Warner Bros. $772,245,583 2022
8 Thor: Love and Thunder Disney $760,928,081 2022
9 The Battle at Lake Changjin II Bona $626,571,697 2022
10 Puss in Boots: The Last Wish Universal $485,261,639 2022
1 Barbie Warner Bros. $1,448,232,531 2023
2 The Super Mario Bros. Movie Universal $1,360,847,665 2023
3 Oppenheimer Universal $975,811,333 2023
4 Guardians of the Galaxy Vol. 3 Disney $845,555,777 2023
5 Fast X Universal $714,875,015 2023
6 Spider-Man: Across the Spider-Verse Sony $690,824,738 2023
7 Full River Red China Film Group $670,491,959 2023
8 Wonka Warner Bros. $634,681,815 2023
9 The Wandering Earth 2 China Film Group $615,023,132 2023
10 Mission: Impossible – Dead Reckoning Part One Paramount $571,125,435 2023
1 Inside Out 2 Disney $1,698,863,816 2024
2 Deadpool & Wolverine Disney $1,338,073,645 2024
3 Moana 2 Disney $1,059,242,164 2024
4 Despicable Me 4 Universal $972,021,410 2024
5 Wicked Universal $758,729,195 2024
6 Mufasa: The Lion King Disney $723,060,982 2024
7 Dune: Part Two Warner Bros. $715,409,065 2024
8 Godzilla x Kong: The New Empire Warner Bros. $572,505,338 2024
9 Kung Fu Panda 4 Universal $547,689,492 2024
10 Sonic the Hedgehog 3 Paramount $492,162,604 2024
1 Ne Zha 2 Beijing Enlight $2,215,690,000[3][4] 2025
2 Zootopia 2 Disney $1,870,309,291 2025
3 Avatar: Fire and Ash 20th Century $1,490,386,712 2025
4 Lilo & Stitch Disney $1,038,027,526 2025
5 A Minecraft Movie Warner Bros. $961,287,780 2025
6 Jurassic World Rebirth Universal $872,428,220 2025
7 Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle Aniplex / Toho / Crunchyroll $793,594,078 2025
8 How to Train Your Dragon Universal $639,866,451 2025
9 F1 Warner Bros. / Apple $634,142,436 2025
10 Superman Warner Bros. $618,723,803 2025