2017-02-17 68 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 chacacter向量中獲得整個歌詞,您可以清理或做任何您喜歡的事情。

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