资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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://cdkjz.cn/article/pogshi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220