Friday, 15 April 2011

how to do for loop on that code in R. I want to do web scraping -



how to do for loop on that code in R. I want to do web scraping -

i have lot of urls address want apply 2 lines of code under:

a <- htmltreeparse("url address",useinternal=t,encoding='utf-8') d <- xpathsapply(a,"//div[@class='text']",xmlvalue)

how it?

i tried it:

urls <- read.table("file.txt") #txt file url's for(i in 1:200){ <- 1:200 c <- 1:200 d <- 1:200 a[i]<-as.character(urls[i,]) c[i] <- htmltreeparse(a[i],useinternal=t,encoding='utf-8') d[i] <- xpathsapply(c[i],"//div[@class='text']",xmlvalue) }

my problem in code above xpathsapply function utilize object of class xmlinternaldocument, c[i] should of class. don't know how can that

try:

urls<-read.table("file.txt") #txt file url's <- c() c <- c() d <- c() for(i in 1:200){ a[i]<- as.character(urls[i,]) c <- htmltreeparse(a[i],useinternal=t,encoding='utf-8') d[i]<- xpathsapply(c,"//div[@class='text']",xmlvalue) }

r for-loop web-scraping

No comments:

Post a Comment