From c4beb5cb7196be9ce02688999b24ed36138f2ad1 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Mon, 24 Jun 2024 16:14:29 -0400 Subject: [PATCH] Changing to webshot2 --- scripts/make_screenshots.R | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R index f239a78..4437360 100644 --- a/scripts/make_screenshots.R +++ b/scripts/make_screenshots.R @@ -53,17 +53,31 @@ if (is.null(opt$base_url)) { base_url <- gsub("/$", "", base_url) } -chapt_df <- ottrpal::get_chapters(base_url = file.path(base_url, "no_toc/")) +# Collect all the chapter pages for the url given +chapt_df <- get_chapters(html_page = file.path(base_url, "no_toc/")) + +# Now take screenshots for each file_names <- lapply(chapt_df$url, function(url) { file_name <- gsub(".html", ".png", file.path(output_folder, basename(url))) - b <- chromote::ChromoteSession$new() - # Get rid of special characters - b$Page$navigate(url, file_name) + + # Open a session + chrome_session <- chromote::ChromoteSession$new() + + # Get rid of special characters because leanpub no like + suppressWarnings(chrome_session$Page$navigate(url, "_", file_name)) file_name <- gsub(":|?|!|\\'", "", file_name) - b$screenshot(file_name) + + # Take the screenshot + chrome_session$screenshot(file.path(file_name)) + message(paste("Screenshot saved:", file_name)) + + # Close it + chrome_session$close() + return(file_name) + }) # Save file of chapter urls and file_names