read_html_table()
returns an HTML table at a specified URL and CSS element
as a dataframe.
Arguments
- url
A string giving the URL to read from.
- css
A string giving the CSS element to select.
SelectorGadget (https://selectorgadget.com/) is a useful tool for finding the code for the CSS element you need. See
rvest::html_element()
for more information.
Examples
# The table used in `get_senate_cloture_votes()`
# NOTE: `get_senate_cloture_votes()` performs some cleaning on this table
read_html_table(url = "https://www.senate.gov/legislative/cloture/clotureCounts.htm",
css = ".cloturecount")
#> # A tibble: 56 × 5
#> Congress Years `Motions Filed` `Votes on Cloture` `Cloture Invoked`
#> <chr> <chr> <chr> <chr> <chr>
#> 1 119 2025-2026 52 48 45
#> 2 118 2023-2024 266 241 227
#> 3 117 2021-2022 336 289 270
#> 4 116 2019-2020 328 298 270
#> 5 115 2017-2018 201 168 157
#> 6 114 2015-2016 128 123 60
#> 7 113 2013-2014 252 218 187
#> 8 112 2011-2012 115 73 41
#> 9 111 2009-2010 137 91 63
#> 10 110 2007-2008 139 112 61
#> # ℹ 46 more rows
# A table from Baseball Reference
read_html_table(url = "https://www.baseball-reference.com/friv/rules-changes-stats.shtml",
css = "#time_of_game")
#> # A tibble: 44 × 8
#> Year G AvgTime `%≤2:30` `%≥3:30` `Avg Tm Btwn PA` `Avg Tm Btwn BIP`
#> <chr> <int> <chr> <dbl> <dbl> <chr> <chr>
#> 1 2025-Mar 62 2:38 35.5 0 2:07 3:14
#> 2 2024-Mar 49 2:42 28.6 2 2:07 3:15
#> 3 2023-Mar 20 2:42 30 5 2:09 3:25
#> 4 2024-Apr 358 2:35 39.1 0 2:06 3:09
#> 5 2024-May 367 2:33 42.2 0.3 2:06 3:05
#> 6 2023-Apr 374 2:36 35 0.3 2:05 3:10
#> 7 2023-May 382 2:37 33.2 0 2:07 3:09
#> 8 2024-Jun 370 2:35 41.4 0.3 2:06 3:06
#> 9 2023-Jun 354 2:39 31.9 0.3 2:08 3:12
#> 10 2024-Jul 337 2:37 36.2 0 2:06 3:08
#> # ℹ 34 more rows
#> # ℹ 1 more variable: `Pos.Pitcher %` <chr>