Output files with new file names in R

90 Views Asked by At

I am using R to get the XML files of these web pages. I have a csv file that has 6000 webpage links and I have a for loop that runs through each webpage link and gets the XML for each webpage link.

Now, I need to create 6000 separate XML file outputs. I need them to be labelled "1page" to "6000page".

Here is the code that I am using:

hf_file <- trial_href_file
hf_file$Href <- as.character(hf_file$Href)

for (i in 1:nrow(hf_file))
{
url2 = hf_file$Href[i]
h21 = GET(url2,user_agent("Gigabot/3.0    (http://www.gigablast.com/spider.html)"))%>% read_html()
data <- xmlParse(h21)
saved_html<- saveXML(data)
#write.csv(paste0(saved_html,i), file = "test.csv")
write.table(saved_html, file=paste0("C:/Users/keerthana.j/Documents/Car Database/Data", Sys.Time(), ".txt"))
#write.table(saved_html, "page_html.txt", sep=",", append = TRUE)
} 

How do I write the output XML txt file with a new name for each webpage link that the for loop runs through?

0

There are 0 best solutions below