I create a dataset that contains all the original songs of Beatles. And I want to get the lyrics of all the songs using genius
package. I use the following code to get lyrics but throw an error.
map(beatles_songs$song, ~ genius_lyrics("The Beatles", ., "simple"))
Error in read_xml.response(x$response, ..., as_html = as_html) :
Not Found (HTTP 404).
In addition: Warning message:
In request_GET(session, url) : Not Found (HTTP 404).
I think maybe this is because the names of songs in the list don't match the songs in genius.com, but I don't know how to check it. So what should I do to get lyrics of all the songs at the same time?
The purrr
package has a number functions that handle warnings and errors. I'd suggest something like the following, inspired by this example:
genius_lyrics_s <- safely(genius::genius_lyrics)
beatles_songs <- tibble(song = c("Mr. Moonlight", "She Loves You", "Under my Thumb", "Octopus's Garden"))
map(beatles_songs$song, ~ genius_lyrics_s("The Beatles", ., "simple")) %>%
map("result") %>%
compact()