【发布时间】:2020-07-05 16:48:16
【问题描述】:
我正在使用循环从网站上抓取表格。无法弄清楚如何将表格组合成一个数据框。以下代码用于抓取一页的相关信息,但我不确定如何将新表添加到第一个(或预先存在的)。谢谢。
for (i in 1:10){
link <- paste0("https://website.com/page",i)
remDr$navigate(link)
# grab the html
pg <- remDr$getPageSource() %>% .[[1]] %>%
read_html()
#grab the correct table
table <- pg %>%
html_nodes("table") %>%
.[2] %>%
html_table(fill = TRUE) %>%
.[[1]]
# combine tables?
}
【问题讨论】:
标签: r for-loop web-scraping