#' Get marriage page
#'
#' Get all marriages from church book in Norway Digital Archives
#'
#' @param id church book id
#' @param pages total number of pages (from Last)
#' @param hits total number of results
#'
#' @return A tibble
#'
#' @author Chris Stubben
#'
#' @examples
#' \dontrun{
#' # Church book from Orkdal local parish 1715-1742
#' m1 <- get_baptisms("16196", 27, 1322)
#' }
#' @export
get_marriages <- function( id, pages, hits){
m1 <- vector("list", hits)
names(m1) <- 1:hits
for (i in 1:pages){
url <- paste0("https://www.digitalarkivet.no/en/search/99/", id, "?rolle=brudgom&page=", i)
doc <- read_html( url)
p1 <- html_nodes(doc, xpath='//div[@class="generic"]/a') %>% html_attr("href")
p1 <- gsub(".*/", "", p1)
message("Downloading ", length(p1), " records from page ", i)
for(j in 1:length(p1)){
x <- married_page( p1[j])
n <- (i-1)*50 + j
message(" ", n)
m1[[n]] <- x
Sys.sleep(sample(1:2, 1))
}
}
bind_rows(m1, .id = "id")
}
#' @describeIn get_marriages Format marriage page
#' @param pid marriage page id
#' @export
married_page<- function(pid){
url <- paste0("https://www.digitalarkivet.no/en/view/327/", pid)
doc <- read_html( url)
x <- html_nodes(doc, xpath='//div[@class="col-xs-12 col-md-6 ssp-semibold"]') %>% html_text(trim=TRUE)
x1 <- matrix(x, ncol=6, byrow=TRUE)
## Baptism date?
x2 <- html_nodes(doc, xpath='//div[@class="col-xs-6 col-sm-3 ssp-semibold"]') %>% html_text(trim=TRUE)
## combine birth year and place (almost always empty?)
## TO DO - fix page -- hv00000000021251
tibble(role = x1[,1], name = x1[,2], residence = x1[,6], position = x1[,3],
birth = apply(x1[,4:5], 1, function(x) paste(x[x!="-"], collapse="; ")),
page = x2[1], year = x2[4], date = x2[6], place = x2[9], pid = pid)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.