# Load the jsonlite and httr libraries for handling JSON data and making HTTP requests. library(jsonlite) library(httr) # Define the URL for the Kramerius API. kramerius5_api <- "https://kramerius.lib.cas.cz/search/api/v5.0/item/" # Define the UUID of the title for which you want to retrieve OCR text. UUID_titul <- "uuid:f24658de-c158-43b0-a41b-5d1761c85cb2" # Construct the URL for retrieving children items of the specified title. request <- paste0(kramerius5_api, UUID_titul, "/children") # Send a GET request to the Kramerius API to retrieve the JSON response. response <- GET(request) # Parse the JSON response into R data structures. parsed_json <- fromJSON(content(response, "text")) # Extract URLs for retrieving OCR text streams. urls <- paste0(kramerius5_api, parsed_json$pid, "/streams/TEXT_OCR") # Retrieve OCR text from each URL and store it in a list. text_list <- lapply(urls, function(url) { response <- GET(url) content(response, "text", encoding = "UTF-8") }) # Convert the list of OCR text into a character vector. text_list <- as.character(text_list) # Write the OCR text to a text file named "stazeny_text_Vesela_Zide.txt" in the current working directory. writeLines(text_list, "stazeny_text_Vesela_Zide.txt")