#coding=utf-8

import os
import urllib
import urllib2
import re
from bs4 import BeautifulSoup
# 利用 urllib.urlretrieve() 函数进行下载。非常方便 import socket
#超时时间
socket.setdefaulttimeout(5) # 一个空文件夹
basedir=r"E:\spring".decode('utf-8')
os.chdir(basedir)
host="http://www.springframework.org" def getFolderName(url):
pattern = re.compile(r'.*/(.*)')
match = pattern.match(url)
# 返回最后一个 / 后面的字符
if match:
return match.group(1) # 存储spring 的集合
list = ['http://www.springframework.org/schema/beans',
'http://www.springframework.org/schema/aop',
'http://www.springframework.org/schema/mvc',
'http://www.springframework.org/schema/p',
'http://www.springframework.org/schema/context',
'http://www.springframework.org/schema/tx'
] # 获取页面中的 文件名称
def getFilesByUrl(url):
#返回列表
list=[]
try:
html = urllib2.urlopen(url)
except Exception as err:
print err
soup = BeautifulSoup(html,"lxml")
for link in soup.find_all('a'):
fileName = link['href']
if not fileName.startswith('/') and (fileName.endswith('xsd') or fileName.endswith('/')):
list.append(fileName)
return list list = getFilesByUrl("http://www.springframework.org/schema")
print list
for url in list:
print url[:-1]
url = "http://www.springframework.org/schema/"+url[:-1]
folder = getFolderName(url)
print folder
if not os.path.exists(folder):
os.mkdir(folder)
files = getFilesByUrl(url)
print files
for fileName in files:
try:
print url+"/"+fileName
urllib.urlretrieve(url+"/"+fileName,folder+"/"+fileName)
except Exception as err:
print err

python 批量下载 spring 的 xsd的更多相关文章

  1. 用Python批量下载DACC的MODIS数据

    本人初次尝试用Python批量下载DACC的MODIS数据,记下步骤,提醒自己,数据还在下载,成功是否未知,等待结果中...... 若有大佬发现步骤有不对之处,望指出,不胜感激. 1.下载Python ...

  2. python批量下载微信好友头像,微信头像批量下载

    #!/usr/bin/python #coding=utf8 # 自行下载微信模块 itchat 小和QQ496631085 import itchat,os itchat.auto_login() ...

  3. 用python批量下载贴吧图片 附源代码

    环境:windows 7 64位:python2.7:IDE pycharm2016.1 功能: 批量下载百度贴吧某吧某页的所有帖子中的所有图片 使用方法: 1.安装python2.7,安装re模块, ...

  4. 用python批量下载图片

    一 写爬虫注意事项 网络上有不少有用的资源, 如果需要合理的用爬虫去爬取资源是合法的,但是注意不要越界,前一阶段有个公司因为一个程序员写了个爬虫,导致公司200多个人被抓,所以先进入正题之前了解下什么 ...

  5. Python 批量下载BiliBili视频 打包成软件

    文章目录 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知识.那么针对这三类人,我给大家 ...

  6. python——批量下载图片

    前言 批量下载网页上的图片需要三个步骤: 获取网页的URL 获取网页上图片的URL 下载图片 例子 from html.parser import HTMLParser import urllib.r ...

  7. Python - 批量下载 IIS 共享的文件

    1.说明 用 IIS 以WEB形式发布了本地文件夹,提供文件下载,并设置了访问权限:默认下载需要点击一个一个的下载,web界面如下: 3.脚本 执行脚本批量下载文件,会在当前目录创建文件夹,并压缩该文 ...

  8. python批量下载图片的三种方法

    一是用微软提供的扩展库win32com来操作IE: win32com可以获得类似js里面的document对象,但貌似是只读的(文档都没找到). 二是用selenium的webdriver: sele ...

  9. 使用Python批量下载Plus上的Podcast

    Plus是一个介绍数学之美与实际应用的网络杂志,其中包含了数学知识.轶闻趣事.历史典故等许多精彩的内容.该杂志恰好有一个Podcast栏目,提供了不少采访与讲座的mp3音频.于是, 我使用Python ...

随机推荐

  1. 触摸事件MultiTouch Events

    备注: userInteractionEnabled = NO hidden = YES alpha = 0.0~0.01    //如果上面三个属性被设置了则无法接收触摸事件 1.- (void)t ...

  2. NDK 编译报错:request for member 'FindClass' in something not a structure or union

    ndk编译 xx.c文件时一直报下面的错误: ”request for member 'FindClass' in something not a structure or union ...” 原因 ...

  3. Solr5.5.3的研究之路 ---1、从Mysql导入数据并创建索引

    公司需要用到全文检索,故使用Solr,也是新人一枚,本人查看的前提是Solr已经安装部署成功,我用的服务器是自带的Jetty 1.创建Collection [root@whoami bin]# ./s ...

  4. 第一天:tomcat相关知识和浏览器的访问机制

    1.tomcat的目录结构 1)bin目录:启动和关闭tomcat以及其他的脚本命令  2)conf目录:存放各种配置文件 a.server.xml配置文件的配置: *<host/>标签: ...

  5. php apc 安装

    APC简介 APC(Alternative PHP Cache)是一个PHP缓存.它在内存中存储PHP页面并且减少了硬盘的I/O.这对于性能的提升十分明显.你甚至可以在CPU使用率下降50%的情况下提 ...

  6. Python中for else注意事项

    假设有如下代码: for i in range(10): if i == 5: print 'found it! i = %s' % i else: print 'not found it ...' ...

  7. 01 json环境搭建【spring + pringMVC】

    1 导包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.o ...

  8. CPU时钟是个什么东西

    CPU时钟说的是频率生成器,可能生成的是方波也可能是其它波. 频率生成器那是什么东西?这教要讲到压电效应了. 压电效应这个词是一个统称,它包括正压电效应和逆压电效应. 传说在很久以前有一个科学家发现了 ...

  9. php学习笔记-foreach循环

    顾名思义,foreach是for each的连写,不是for reach.意思就是对数组中的每个元素都要处理一次. foreach只能用来处理数组. 有两种用法,先看第一种. foreach(arra ...

  10. 算法Sedgewick第四版-第1章基础-002一些工具类算法(Euclid’s algorithm)

    1. //Euclid’s algorithm public static int gcd(int p, int q) { if (q == 0) return p; int r = p % q; r ...