Web Scraping with R: проблема усечения

Как новичок, я в настоящее время работаю с веб-скребком с помощью R, используя пакет 'rvest'. Моя цель - получить текст любой песни с сайта www.musixmatch.com. Это моя попытка:

library(rvest)
url <- "https://www.musixmatch.com/lyrics/Red-Hot-Chili-Peppers/Can-t-Stop"
musixmatch <- read_html(url)
lyrics <- musixmatch%>%html_nodes(".mxm-lyrics__content")%>%html_text()

Этот код создает вектор "текст" с 2 строками, содержащий текст:

[1] "Can't stop addicted to the shindig\nChop top he says I'm gonna win big\nChoose not a life of imitation" 
[2] "Distant cousin to the reservation\n\nDefunkt the pistol that you pay for\nThis punk the feeling that you stay for\nIn time I want to be your best friend\nEastside love is living on the Westend\n\nKnock out but boy you better come to\nDon't die you know the truth is some do\nGo write your message on the pavement\nBurn so bright I wonder what the wave meant\n\nWhite heat is screaming in the jungle\nComplete the motion if you stumble\nGo ask the dust for any answers\nCome back strong with 50 belly dancers\n\nThe world I love\nThe tears I drop\nTo be part of\nThe wave can't stop\nEver wonder if it's all for you\nThe world I love\nThe trains I hop\nTo be part of\nThe wave can't stop\n\nCome and tell me when it's time to\n\nSweetheart is bleeding in the snow cone\nSo smart she's leading me to ozone\nMusic the great communicator\nUse two sticks to make it in the nature\nI'll get you into penetration\nThe gender of a generation\nThe birth of every other nation\nWorth your weight the gold ... <truncated>

Проблема в том, что 2-й ряд усекается в какой-то момент. Из того, что я знаю о rvest, нет параметра для настройки усечения. Также я не смог найти в интернете ничего по этому поводу. Кто-нибудь знает, как настроить / отключить усечение для этой функции? Заранее большое спасибо!

С наилучшими пожеланиями,

январь

1 ответ

Я думаю, что лучше скопировать и вставить текст в свой блокнот или Wordpad. Сохранить как текстовый файл

Затем используйте readLines функция, она печатает наше предупреждающее сообщение, но я смог получить весь текст в векторном формате 84x1, который вы можете очистить или сделать что угодно.

words <- readLines("redhot.txt")
> head(words)
  [1] "Can't stop addicted to the shindig"     
  [2] "Chop top he says I'm gonna win big"     
  [3] "Choose not a life of imitation"         
  [4] "Distant cousin to the reservation"      
  [5] "Defunkt the pistol that you pay for"    
  [6] "This punk the feeling that you stay for"

Здесь нет проблем с усечением.

Другие вопросы по тегам