2017-02-17 8 views
-1

初心者として、私は現在、rvestパッケージを使用してRを使用してWebスクレイピングを行っています。私の目標は「www.musixmatch.com」から歌の歌詞を得ることです。これは私の試みです:Rを使用したWebスクレイピング:切り捨ての問題

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

それ自体が切り捨てられているのですか、それとも印刷されただけですか?テキストファイルに書き込むことで、完全に見ることができます。 –

+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

@ ban benediktまたはこれを試してください:strsplit(lyrics、 "\ n") – mikeymike

関連する問題