knitr::opts_chunk$set(echo = TRUE, eval = F)
From: Scraping Gdpr Fines
library(rvest)
library(tidyverse)
link <- "https://www.privacyaffairs.com/gdpr-fines/"
page <- read_html(link)
temp <- page %>%
html_nodes("script") %>% # the nodes came after each "<" :
.[9] %>%
rvest::html_text()
ends <- str_locate_all(temp, "\\]")
starts <- str_locate_all(temp, "\\[")
table_1 <- temp %>%
stringi::stri_sub(from = starts[[1]][1,2], to = ends[[1]][1,1]) %>%
str_remove_all("\n") %>%
str_remove_all("\r") %>%
jsonlite::fromJSON()
table2 <- temp %>%
stringi::stri_sub(from = starts[[1]][2,2], to = ends[[1]][2,1]) %>%
str_remove_all("\n") %>%
str_remove_all("\r") %>%
jsonlite::fromJSON()