R: rvest: scraping a dynamic ecommerce page -
i'm using rvest
in r scraping. know html , css.
i want prices of every product of uri:
http://www.linio.com.co/tecnologia/celulares-telefonia-gps/
the new items load go down on page (as scrolling).
what i've done far:
linio_celulares <- html("http://www.linio.com.co/celulares-telefonia-gps/") linio_celulares %>% html_nodes(".product-itm-price-new") %>% html_text()
and need, 25 first elements (those load default).
[1] "$ 1.999.900" "$ 1.999.900" "$ 1.999.900" "$ 2.299.900" "$ 2.279.900" [6] "$ 2.279.900" "$ 1.159.900" "$ 1.749.900" "$ 1.879.900" "$ 189.900" [11] "$ 2.299.900" "$ 2.499.900" "$ 2.499.900" "$ 2.799.000" "$ 529.900" [16] "$ 2.699.900" "$ 2.149.900" "$ 189.900" "$ 2.549.900" "$ 1.395.900" [21] "$ 249.900" "$ 41.900" "$ 319.900" "$ 149.900"
question: how elements of dynamic section?
i guess, scroll page until elements loaded , use html(url). seems lot of work (i'm planning of doing on different sections). there should programmatic work around.
any hint welcome!
as @nrussell suggested, can use rselenium
programatically scroll down page before getting source code.
you example do:
library(rselenium) library(rvest) #start rselenium checkforserver() startserver() remdr <- remotedriver() remdr$open() #navigate page remdr$navigate("http://www.linio.com.co/tecnologia/celulares-telefonia-gps/") #scroll down 5 times, waiting page load @ each time for(i in 1:5){ remdr$executescript(paste("scroll(0,",i*10000,");")) sys.sleep(3) } #get page html page_source<-remdr$getpagesource() #parse html(page_source[[1]]) %>% html_nodes(".product-itm-price-new") %>% html_text()
Comments
Post a Comment