【发布时间】:2020-12-10 23:40:41
【问题描述】:
我正在尝试搜索这个URL 以获取加拿大前 50 名 soundcloud 艺术家的名字。
使用 SelectorGadget,我选择了艺术家的名字,它告诉我路径是“.sc-link-light”。
我的第一次尝试如下:
library(rvest)
library(stringr)
library(reshape2)
soundcloud <- read_html("https://soundcloud.com/charts/top?genre=all-music&country=CA")
artist_name <- soundcloud %>% html_nodes('.sc-link-light') %>% html_text()
它产生了艺术家名称为 0 的列表。
我第二次尝试将最后一行改为:
artist_name <- soundcloud %>% html_node(xpath='//*[contains(concat( " ", @class, " " ), concat( " ", ".sc-link-light", " " ))]') %>% html_text()
这又产生了同样的结果。
我到底做错了什么?我相信这应该给我列表中的艺术家姓名。 任何帮助表示赞赏,谢谢。
【问题讨论】:
标签: r web-scraping rvest