【发布时间】:2017-07-07 03:47:38
【问题描述】:
作为初学者,我目前正在使用“rvest”包使用 R 进行网络抓取。我的目标是从“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>
问题是第二行在某些时候被截断。根据我对 rvest 的了解,没有调整截断的参数。另外,我在互联网上找不到有关此问题的任何信息。有人知道如何调整/禁用此功能的截断吗?提前非常感谢!
最好的问候,
一月
【问题讨论】:
-
它是自己截断的,还是只是打印显示?尝试写入文本文件,以便完整查看。
-
其实,也许这样可以解决你的问题?:stackoverflow.com/questions/36800475/…
-
我无法重现该问题。
-
@sebastian-c,我不敢相信事情就这么简单:非常感谢!
-
"您同意您不会:修改、改编、翻译或反向工程 Musixmatch 或其内容的任何部分,或使用任何机器人、蜘蛛、站点搜索/检索应用程序,或其他设备来检索或索引网站和/或应用程序的任何部分”。 SO上没有人阅读EULA/ToC/ToS吗?
标签: r web-scraping rvest truncation