【问题标题】:Annotate CSV after web-scraping and before saving在网络抓取之后和保存之前注释 CSV
【发布时间】:2019-12-12 23:10:22
【问题描述】:

我正在从网站的多个 URL 中抓取大量 html 表,并将它们存储到单独的 csv 文件中。抓取完成后,我将所有 csv 文件合并为一个。因此,我希望每个表都单独标识。

所以,我想知道是否有机会在 CSV 文件的单元格 A1 中注释/添加额外的输入(例如“table1”),或者使用文本输入(如“table1”)自动向 csv 文件添加另一列" 在 K1:K12 列中。

library(rvest)
url <- "URL of website" 
page <- read_html(url)
table <- html_table(page, fill = TRUE)
write.csv2(table, "table.csv")

提前谢谢你!

【问题讨论】:

    标签: r web-scraping rvest


    【解决方案1】:

    将 ID 列添加到 table,然后将其保存到 csv 中

    library(rvest)
    url <- "URL of website" 
    page <- read_html(url)
    table <- html_table(page, fill = TRUE)
    table <- cbind(id="table1", table)
    write.csv2(table, "table.csv")
    

    【讨论】:

      猜你喜欢
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多