我目前正在美化这个网站:
https://uws-community.symplicity.com/index.php?s=student_group
因此,网站上的每个俱乐部都有一个特定的id,还有一个“更多信息”链接。我已经找到了从div.grpl-grp.clearfix类中抓取每个id的方法,但我想使用这些id从具有特定id的元素的"more info“链接(例如fb链接)中抓取数据。
这样做的语法是什么?
发布于 2018-08-27 13:08:13
“更多信息”文本的类是“grpl-More in”,链接在<a>
标记中。所以我们可以这样做
library(rvest)
url <- 'https://uws-community.symplicity.com/index.php?s=student_group'
page <- html_session(url)
html_nodes(page, "li.grpl-moreinfo a") %>% html_attr("href")
#[1] "?mode=form&id=5bf9ea61bc46eaeff075cf8043c27c92&tab=profile"
#[2] "?mode=form&id=17e4ea613be85fe019efcf728fb6361d&tab=profile"
#[3] "?mode=form&id=d593eb48fe26d58f616515366a1e677b&tab=profile"
...
这也可以在一个链操作中完成,如:
url %>%
read_html() %>%
html_nodes("li.grpl-moreinfo a") %>%
html_attr("href")
#[1] "?mode=form&id=5bf9ea61bc46eaeff075cf8043c27c92&tab=profile"
#[2] "?mode=form&id=17e4ea613be85fe019efcf728fb6361d&tab=profile"
#[3] "?mode=form&id=d593eb48fe26d58f616515366a1e677b&tab=profile"
...
https://stackoverflow.com/questions/52032772
复制相似问题