本文
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"
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())
原文地址:https://www.jb51.cc/html/224571.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。