i am new to r,, i want to scrape some data form olx.com but i couldn't get the required data except some data can any one help me in pointing out my mistakes and help me to fix them just got data of "title", "time", "city" i need price , category and many other things `library(XML) for(i in 1:2) { fileURL <- paste("http://ift.tt/1Zjnk9N",i, sep="")
doc <- htmlTreeParse(fileURL , useInternal = TRUE)
title <- xpathSApply(doc,"//h3[@class='large lheight20 margintop10']/a/span" , xmlValue)
price <- xpathSApply(doc, "//p[@class='price x-large margintop10']/strong",xmlValue)
detailLink <- xpathSApply(doc , "//h3[@class='large lheight20 margintop10']/a/@href")
category <- xpathSApply(doc , "//p[@class='color-9 lheight14 margintop3']/small" , xmlValue)
verified <- xpathSApply(doc , "//td[@class='wwnormal tright td-price']/span[@class='icon verified-num-pc-itempage marginright5']")
views <- xpathSApply(doc , "//div[@class='pdingtop10']/strong" , xmlValue)
date <- xpathSApply(doc, "//p[@class='color-9 lheight14 margintop3 small']" , xmlValue)
city <- xpathSApply(doc , "//p[@class='color-9 lheight14 margintop3']/small/span" , xmlValue)
description <- xpathSApply(doc , "//p[@class='pding10 lheight20 large']" , xmlValue)
dfrm <- data.frame(title = title,price = price ,city = city , date = date,detailLink = detailLink)
write.table(dfrm, file="tar.csv", append=TRUE, col.names = FALSE, sep = ',') }`
Aucun commentaire:
Enregistrer un commentaire