i would like to download all of images from this site but after downloading photos all are corrupted. What i should do to download them successfully?
My code:
library(XML)
dir.create('c:/photos')
urls<-paste("http://thedevilsguard.tumblr.com/page/",1:1870,sep="")
doc<-htmlParse(urls[1])
links<-unique(unlist(xpathApply(doc,'//div[@class="timestamp"]/a',xmlGetAttr,'href')))
for (i in 1:length(links)){
doc2<-htmlParse(links[i])
link<-xpathApply(doc2,'//div[@class="centre photopage"]//p//img',xmlGetAttr,'src')[[1]][1]
download.file(link,paste("C:/photos/",basename(link),""))
}
First, try and download one. Do this:
link = "http://29.media.tumblr.com/tumblr_m0q2g8mhGK1qk6uvyo1_500.png"
download.file(link,basename(link))
Does that work?
I notice its a PNG and NOT a JPEG, so maybe you are trying to read it in as a JPEG.
So it looks you are under Windows. When you download binary files, you have to specify the mode to be binary, e.g.
download.file(link, ..., mode = 'wb')
see ?download.file
for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With