R语言设置CRAN使用清华大学镜像,命令如下:options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))
soupR.py 代码如下
# -*- coding: utf-8 -*-
""" 批量下载 map* R语言库包 """
from urllib import request, parse
import os
import bs4
localDir = 'D:/test/'
URL = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/4.3/"
page = request.urlopen(URL).read()
soup = bs4.BeautifulSoup(page, features='html.parser')
for a in soup.findAll('a'):
if a is not None:
text = a.text.strip()
#if re.search('map',text):
if text.startswith('map'):
href = a.get('href')
if href.endswith('.zip'):
#print(href)
localFile = localDir + text
if os.path.exists(localFile):
print(localFile,'is exists')
else:
try:
# 按照url进行下载文件,并保存到本地目录
request.urlretrieve(URL+href, localFile)
print(href,'is download')
except:
continue
运行 python soupR.py
mapSpain_0.8.0.zip is download
mapStats_3.1.zip is download
mapaccuracy_0.1.1.zip is download
mapbayr_0.10.0.zip is download
mapboxapi_0.5.3.zip is download
mapboxer_0.4.0.zip is download
mapcan_0.0.1.zip is download
mapchina_0.1.0.zip is download
mapdata_2.3.1.zip is download
mapdeck_0.3.4.zip is download
mapedit_0.6.0.zip is download
mapfit_1.0.0.zip is download
mapi_1.0.5.zip is download
mapiso_0.3.0.zip is download
maplegend_0.1.0.zip is download
mapme.biodiversity_0.4.0.zip is download
mapmisc_2.0.3.zip is download
mapping_1.4.1.zip is download
mappings_0.1.zip is download
mapplots_1.5.2.zip is download
mappoly_0.3.3.zip is download
mappp_1.0.0.zip is download
mapproj_1.2.11.zip is download
mapsFinland_0.2.2.zip is download
mapsPERU_2.0.0.zip is download
mapsRinteractive_2.0.1.zip is download
maps_3.4.2.zip is download
mapsapi_0.5.4.zip is download
mapscanner_0.0.6.zip is download
mapsf_0.8.0.zip is download
maptiles_0.6.1.zip is download
maptpx_1.9-7.zip is download
maptree_1.4-8.zip is download
mapview_2.11.2.zip is download