python : 批量下载R语言库包

11 篇文章 0 订阅

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值