soupR.py 代码例如以下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29# -*- coding: cp936 -*- import urllib import urllib2 import os, re from BeautifulSoup import BeautifulSoup localDir = 'D:/test/' URL = "http://cran.dataguru.cn/bin/windows/contrib/3.1/" page = urllib2.urlopen(URL) soup = BeautifulSoup(page) page.close() 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进行下载文件,并保存到本地文件夹 urllib.urlretrieve(URL+href,localFile) print href,'is download' except Exception,e: continue
最后
以上就是追寻火车最近收集整理的关于python : 批量下载R语言库包的全部内容,更多相关python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复