- 已编辑
从网页上批量下载和整理图片,书中代码如下:
也复制了该链接到浏览器里面试了,浏览器能正常进去,但是文件却显示为空,不知道是什么原因?
> urlink <- 'http://www.biomet.co.at/pictures/'
> aa <- readLines(urlink, encoding = 'UTF-8')
Warning message:
In readLines(urlink, encoding = "UTF-8") :
incomplete final line found on 'http://www.biomet.co.at/pictures/'
>
> linkformat <- 'src = "http://www.biomet.co.at/wp/wp-content/gallery'
> bb <- aa[grep(linkformat, aa)]
>
> for(i in 1:length(bb))
+ bb[i] <- substring(
+ bb[i],
+ regexpr("http", bb[i])[1],
+ regexpr(".jpg\"", bb[i])[1] + 3)
>
> bb <- unique(bb)
> bb
[1] NA
> length(bb)
[1] 1
> writeLines(bb, 'c:/r4r/links.txt')
>
> stname <- substring(bb, 47, 50)
> stname <- stname[-which(stname == '')]
> for(i in unique(stname))
+ dir.create(paste('c:/r4r', i, sep = ''))
>
> for(i in 1:length(bb)) {
+ download.file(url = bb[i],
+ destfile = paste('c:/r4r/', stname[i], '/',
+ stname[i], i, '.jpg', sep = " "),
+ method = 'curl', quiet = T)
+ print(paste(i, 'of', length(bb), 'downloaded.'))
+ }
Error in download.file(url = bb[i], destfile = paste("c:/r4r/", stname[i], :
'curl' call had nonzero exit status
以上为所有代码,有朋友碰到过这样的问题麽,烦请赐教!不胜感激!