2017-02-17 20 views
-1

초보자로서 저는 현재 'rvest'패키지를 사용하여 R로 스크래핑하는 웹 작업을하고 있습니다. 내 목표는 '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에 대해 알고있는 것으로부터 잘라내기를 조정할 매개 변수는 없습니다. 또한 인터넷에서이 문제에 관해서는 아무 것도 찾을 수 없었습니다. 아무도 조정/해제 기능을이 기능에 대한 방법을 알고 있습니까? 많은 감사드립니다!

안부,

+1

자체가 잘 리거나 인쇄물 만 표시됩니까? 전체 텍스트 파일을 볼 수 있도록 텍스트 파일에 쓰십시오. –

+1

사실, 아마도이 문제가 해결 될 수 있습니까? : http://stackoverflow.com/questions/36800475/avoid-string-printed-to-console-getting-truncated-in-rstudio –

+0

문제를 재현 할 수 없습니다. – Dason

답변

-1

나는 당신의 메모장이나 워드 패드로 복사 가사를 붙여 그것의 더 나은 생각합니다. .txt 파일로 저장

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" 

여기에 잘림 문제가 없습니다.

+0

@jan benedikt 또는 시도해주세요. strsplit (가사, "\ n") – mikeymike