Scrapes survey tables and performs sanitation to output tidy data

scrape_wahlrecht(
  address = "https://www.wahlrecht.de/umfragen/emnid.htm",
  parties = c("CDU", "SPD", "GRUENE", "FDP", "LINKE", "PIRATEN", "AFD", "BSW",
    "SONSTIGE")
)

scrape_by(
  address = "https://www.wahlrecht.de/umfragen/landtage/bayern.htm",
  parties = c("CSU", "SPD", "GRUENE", "FDP", "LINKE", "PIRATEN", "FW", "AFD", "SONSTIGE")
)

scrape_rp(
  address = "https://www.wahlrecht.de/umfragen/landtage/rheinland-pfalz.htm",
  parties = c("CDU", "SPD", "GRUENE", "FDP", "LINKE", "AFD", "FW", "SONSTIGE"),
  ind_row_remove = -c(1:3)
)

scrape_ltw(
  address = "https://www.wahlrecht.de/umfragen/landtage/niedersachsen.htm",
  parties = c("CDU", "SPD", "GRUENE", "FDP", "LINKE", "PIRATEN", "FW", "AFD", "BSW",
    "SONSTIGE"),
  ind_row_remove = -c(1:2)
)

Arguments

address

http-address from which tables should be scraped.

parties

A character vector containing names of parties to collapse.

ind_row_remove

Negative vector of rows that will be skipped at the beginning.

Value

A tibble with one row per survey date and columns for date, respondents, and one column per party containing the percentage of votes.

Examples

# \donttest{
library(coalitions)
library(dplyr)
scrape_wahlrecht() %>% slice(1:5)
#> Warning: There were 7 warnings in `mutate()`.
#> The first warning was:
#>  In argument: `across(all_of(parties), extract_num)`.
#> Caused by warning:
#> ! NAs introduced by coercion
#>  Run `dplyr::last_dplyr_warnings()` to see the 6 remaining warnings.
#> Warning: There was 1 warning in `mutate()`.
#>  In argument: `datum = dmy(.data$datum)`.
#> Caused by warning:
#> !  1 failed to parse.
#> # A tibble: 5 × 12
#>   date       start      end          cdu   spd greens   fdp  left   afd   bsw
#>   <date>     <date>     <date>     <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2013-09-29 2013-09-24 2013-09-26    43    26      7     3     9     6    NA
#> 2 2013-10-06 2013-09-26 2013-10-01    42    25      8     4     9     6    NA
#> 3 2013-10-13 2013-10-04 2013-10-09    42    25      9     3    10     6    NA
#> 4 2013-10-20 2013-10-10 2013-10-16    42    25      9     3    10     5    NA
#> 5 2013-10-27 2013-10-17 2013-10-23    41    26     10     3     9     5    NA
#> # ℹ 2 more variables: others <dbl>, respondents <dbl>
# }
if (FALSE) { # \dontrun{
# Niedersachsen
scrape_ltw() %>% slice(1:5)
# Hessen
scrape_ltw("https://www.wahlrecht.de/umfragen/landtage/hessen.htm", ind_row_remove=-c(1)) %>%
 slice(1:5)
} # }