vignettes/scrape_michigan_lakes.Rmd
scrape_michigan_lakes.Rmd
## Loading required package: maps
res <- WikipediR::page_info("en", "wikipedia",
page = "Category:Lakes of Michigan")
res <- xml2::read_html(res$query$pages[[1]]$canonicalurl)
res <- rvest::html_nodes(res, "#mw-pages .mw-category")
res <- rvest::html_nodes(res, "li")
res <- rvest::html_nodes(res, "a")
res <- rvest::html_attr(res, "title")
data.frame
res_df_names <- unique(unlist(lapply(res, names)))
res_df <- data.frame(matrix(NA, nrow = length(res),
ncol = length(res_df_names)))
names(res_df) <- res_df_names
for (i in seq_len(length(res))) {
dt_pad <- data.frame(matrix(NA, nrow = 1,
ncol = length(res_df_names) - ncol(res[[i]])))
names(dt_pad) <- res_df_names[!(res_df_names %in% names(res[[i]]))]
dt <- cbind(res[[i]], dt_pad)
dt <- dt[, res_df_names]
res_df[i, ] <- dt
}