library(rvest)
library(robotstxt)
library(dplyr)
library(purrr)
paths_allowed("https://en.wikipedia.org/wiki/2026_in_film")
## [1] TRUE
TRUE means scraping this page is allowed under
Wikipedia’s robots exclusion protocol.
page <- read_html("https://en.wikipedia.org/wiki/2026_in_film")
films_2026 <- page |>
html_element("table.wikitable") |>
html_table()
films_2026
## # A tibble: 10 × 4
## Rank Title Distributor `Worldwide gross`
## <int> <chr> <chr> <chr>
## 1 1 Spider-Man: Brand New Day † Sony $2,523,147,515
## 2 2 The Odyssey Universal $1,804,356,298
## 3 3 Toy Story 5 Disney $1,149,474,196
## 4 4 Michael Lionsgate / Universal $1,028,703,388
## 5 5 The Super Mario Galaxy Movie Universal $1,013,278,851
## 6 6 The Devil Wears Prada 2 20th Century $693,492,689
## 7 7 Project Hail Mary Amazon MGM / Sony $685,040,805
## 8 8 Pegasus 3 Maoyan $656,459,523
## 9 9 Minions & Monsters Universal $530,319,698
## 10 10 Obsession Focus / Universal $524,535,537
scrape_hg <- function(yr) {
url <- paste0("https://en.wikipedia.org/wiki/", yr, "_in_film")
Sys.sleep(1)
read_html(url) |>
html_element("table.wikitable") |>
html_table() |>
mutate(across(everything(), as.character),
Year = yr)
}
hg_films <- map(2020:2025, scrape_hg) |>
list_rbind()
count(hg_films, Year)
## # A tibble: 6 × 2
## Year n
## <int> <int>
## 1 2020 10
## 2 2021 10
## 3 2022 10
## 4 2023 10
## 5 2024 10
## 6 2025 10
hg_films
## # A tibble: 60 × 5
## Rank Title Distributor `Worldwide gross` Year
## <chr> <chr> <chr> <chr> <int>
## 1 1 Demon Slayer: Kimetsu no Yaiba Mug… Toho / Ani… $507,127,293[4] 2020
## 2 2 The Eight Hundred CMC Pictur… $461,421,559 2020
## 3 3 My People, My Homeland China Lion $433,241,288[5] 2020
## 4 4 Bad Boys for Life Sony $426,505,244 2020
## 5 5 Tenet Warner Bro… $365,309,519 2020
## 6 6 Sonic the Hedgehog Paramount $319,715,683 2020
## 7 7 Dolittle Universal $251,410,631 2020
## 8 8 Jiang Ziya Beijing En… $243,883,429 2020
## 9 9 A Little Red Flower HG Enterta… $238,600,000[6][… 2020
## 10 10 Shock Wave 2 Universe F… $226,400,000 2020
## # ℹ 50 more rows