2017-02-17 5 views
-1

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

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> 

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

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

Jan

+1

Урезано ли оно, или только распечатка? Попробуйте написать текстовый файл, чтобы вы могли его просмотреть. –

+1

На самом деле, может быть, это решит вашу проблему ?: http://stackoverflow.com/questions/36800475/avoid-string-printed-to-console-getting-truncated-in-rstudio –

+0

Я не могу воспроизвести проблему. – Dason

ответ

-1

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

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

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" 

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

+0

@jan benedikt или попробуйте это: strsplit (lyrics, "\ n") – mikeymike

Смежные вопросы