R/webscrap_musics.R

Defines functions webscrap_musics

#' webscrap_musics
#'
#' @description Funcao para montagem da tabela de musicas
#'
#' @return Um dataframe com todas as musicas, para cada artista do genero gospel, 
#' encontradas no portal do vagalume.
#' 
#'
#' @noRd
webscrap_musics <- function() {
  load("data/artists.rda")
  future::plan(future::multisession, workers = 10) 
  furrr::future_map_dfr(1:nrow(artists), function(id_artist) {
    
    artist <- artists[id_artist,]
    
    lyrics_artist <- tryCatch({
      u <- glue::glue("https://www.vagalume.com.br{artist$href}")
      
      nodeset_musics <- rvest::read_html(u) |> 
        rvest::html_elements(xpath = "//ol[@id='alfabetMusicList']") |> 
        rvest::html_elements(xpath = "//a[contains(@class, 'nameMusic')]")
      
      name_artist <- artist$name
      
      names_musics <- nodeset_musics |> 
        rvest::html_text()
      
      hrefs_musics <- nodeset_musics |> 
        rvest::html_attr(name = "href")
      
      tibble::tibble(
        artist = name_artist, music = names_musics, href = hrefs_musics
      )
    }, error = function(e) tibble::tibble(artist = NA, music = NA, href = NA))
    
    return(lyrics_artist)
    
  }, .progress = TRUE)
}
damarals/gospel.slides documentation built on March 19, 2022, 10:50 a.m.