Question 5: Check scraping permission

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

paths_allowed(url)
## [1] TRUE

Question 6: Highest-grossing films of 2026

# Find the table with a worldwide gross column
get_films <- function(year) {
  url <- paste0("https://en.wikipedia.org/wiki/", year, "_in_film")

  page <- read_html(url)

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

  matches <- vapply(tables, function(tbl) {
    any(grepl("Worldwide gross", names(tbl), ignore.case = TRUE))
  }, logical(1))

  if (!any(matches)) {
    stop(paste("Highest-grossing films table not found for", year))
  }

  films <- tables[[which(matches)[1]]]

  films <- films |>
    mutate(across(everything(), as.character),
           year = year)

  return(films)
}

films_2026 <- get_films(2026)

knitr::kable(films_2026)
Rank Title Distributor Worldwide gross year
1 Spider-Man: Brand New Day † Sony $2,523,147,515 2026
2 The Odyssey Universal $1,804,356,298 2026
3 Toy Story 5 Disney $1,149,474,196 2026
4 Michael Lionsgate / Universal $1,028,703,388 2026
5 The Super Mario Galaxy Movie Universal $1,013,278,851 2026
6 The Devil Wears Prada 2 20th Century $693,492,689 2026
7 Project Hail Mary Amazon MGM / Sony $685,040,805 2026
8 Pegasus 3 Maoyan $656,459,523 2026
9 Minions & Monsters Universal $530,319,698 2026
10 Obsession Focus / Universal $524,535,537 2026

Question 8: Highest-grossing films from 2020 to 2025

film_tables <- list()

for (yr in 2020:2025) {
  film_tables[[as.character(yr)]] <- get_films(yr)
  Sys.sleep(1)
}

hg_films <- bind_rows(film_tables)

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