Created
August 12, 2022 04:08
-
-
Save vizowl/59268a8f7a152d86d7b600c5bbb4af23 to your computer and use it in GitHub Desktop.
Extract a listing of all csvs from https://www.stats.govt.nz/large-datasets/csv-files-for-download/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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