rimageweb-scrapingdecodedata-uri

Getting image from data uri


I'm trying to scrap data and one of the data is also the image, which is embeded in data uri. I can't figure it out hot to do this with r.

library(rvest)
webUrl<-"https://portaltramites.inpi.gob.ar/Marcas/Logo?Acta=3363531"

imgscr<- read_html(webUrl) %>%
html_node(xpath = '//*/img') %>%
html_attr('src')

img<-gsub("data:image/gif;base64,","",imgsrc, fixed=true)

head(img)

#now I'm stuck

Solution

  • library(rvest)
    library(openssl)
    library(magick)
    
    pg <- read_html("https://portaltramites.inpi.gob.ar/Marcas/Logo?Acta=3363531")
    
    img <- html_nodes(pg, "img")
    
    img_src <- html_attr(img, "src")
    img_src <- gsub("^data.*base64,", "", img_src)
    
    image_read(base64_decode(img_src))
    

    You can then use other magick package functions to save/manipulate/etc.