setwd("E:/r_w/")
#设置工作目录
library(RCurl)
html=getURL("http://rfunction.com/code/1202/")
#下载页面
temp=strsplit(html,"<li><a href=\"")[[1]]
#分割页面
files=strsplit(temp,"\"")
#分割页面
files=lapply(files,function(x){x[1]})
#此时files为list类型,取files中的每个元素的第一个元素
files=unlist(files)
#转换成非list类型
files=files[-(1:2)]
#去除第一第二行
base="http://rfunction.com/code/1202/"
for(i in 1:length(files))
{
url=paste(base,files[i],sep='')
temp=getBinaryURL(url)
#下载文件
note=file(paste("1202",files[i],sep='.'),open="wb")
#设置目录
writeBin(temp,note)
#写入
close(note)
Sys.sleep(2)
}
R网络爬虫之批量下载
最新推荐文章于 2023-08-20 20:43:18 发布