0

I am web-scraping numerous html tables from multiple URLs of a website and store them into individual csv files. After the scraping is done, I merge all csv files into one. Therefore, I would like to have each table individually IDed.

So, I was wondering if there is any chance to either annotate/add an additional input (e.g. "table1") into cell A1 of the CSV file or to automatically add another column to the csv file with text input like "table1" in column K1:K12.

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

Thank you in advance!

TomTe
  • 153
  • 8

1 Answers1

1

Add ID column to table just before saving it into 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")
nurandi
  • 1,556
  • 1
  • 10
  • 17