重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

python批量下载文件

#!/usr/bin/python
# _*_ coding: utf-8 _*_

'''
Created on 2018年8月22日
'''

import urllib
import urllib2
import re

req = urllib2.Request('http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/')
# req = urllib2.Request('http://www.cvpapers.com/cvpr2014.html')
f = urllib2.urlopen(req)
localDir = 'E:\download\\'
urlList = []
for eachLine in f:
    line = eachLine.strip()
    if re.match('.*rpm.*', line):
#         print(line)
        wordList = line.split('\"')
        for word in wordList:
            if re.match('.*\.rpm$', word):
#                 print(word)
                urlList.append(word)

for everyFile in urlList:
#     print (everyFile)
    everyURL = "http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/"+everyFile
#     print(everyURL)
    localFile = localDir + everyFile
    try:            
      urllib.urlretrieve(everyURL, localFile) #按照url进行下载,并以其文件名存储到本地目录 
    except Exception,e: 
      continue

网页题目:python批量下载文件
路径分享:http://cqcxhl.cn/article/pogshi.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP