在R和rvest中删除多个链接的HTML表

本文 http://www.ajnr.org/content/30/7/1402.full包含四个链接到html表,我想用rvest刮.

在css选择器的帮助下:

"#T1 a"

有可能到这样的第一个表:

library("rvest")
html_session("http://www.ajnr.org/content/30/7/1402.full") %>%
follow_link(css="#T1 a") %>%
html_table() %>%
View()

css选择器:

".table-inline li:nth-child(1) a"

使得可以选择包含链接到四个表的标签的所有四个html节点:

library("rvest")
html("http://www.ajnr.org/content/30/7/1402.full") %>%
html_nodes(css=".table-inline li:nth-child(1) a")

如何循环遍历此列表并一次检索所有四个表?最好的方法是什么?

解决方法

这是一种方法
library(rvest)

url <- "http://www.ajnr.org/content/30/7/1402.full"
page <- read_html(url)

# First find all the urls
table_urls <- page %>% 
  html_nodes(".table-inline li:nth-child(1) a") %>%
  html_attr("href") %>%
  xml2::url_absolute(url)

# Then loop over the urls,downloading & extracting the table
lapply(table_urls,. %>% read_html() %>% html_table())

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些