Skip to content

Instantly share code, notes, and snippets.

@vizowl
Created August 12, 2022 04:08
Show Gist options
  • Save vizowl/59268a8f7a152d86d7b600c5bbb4af23 to your computer and use it in GitHub Desktop.
Save vizowl/59268a8f7a152d86d7b600c5bbb4af23 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(rvest)
library(jsonlite)
library(rlang)
all_csvs <-
read_html("https://www.stats.govt.nz/large-datasets/csv-files-for-download/") |>
html_element('#pageViewData') |>
html_attr('data-value') |>
parse_json() |>
pluck("PageBlocks") |>
discard(~ !has_name(., 'BlockDocuments')) |>
map_dfr(function(l) {
tibble(
Section = l$Title,
Title = l$BlockDocuments |> map_chr(pluck("Title")),
Path = l$BlockDocuments |> map_chr(pluck("DocumentLink"))
)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment