python抓取链接并下载(无需认证)
2015-10-27 20:43
447 查看
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import urllib2,urllib
>>> url = 'http://blog.pythonlibrary.org/wp-content/uploads/2012/06/'
>>> cunchu='C:\Users\Administrator\Desktop\python-test-xiazai'
>>> req = urllib2.Request(url)
>>> content = urllib2.urlopen(req).read()
>>> import re
>>> match = re.compile(r'(?<=href=["]).*?\.zip(?=["])')
>>> rawlv2 = re.findall(match,content)
>>> print rawlv2
['form_submission.zip', 'wxDbViewer.zip', 'wxDnD.zip']
>>> import os
>>> for x in rawlv2:
cunurl=os.path.join(cunchu,x)
urllib.urlretrieve(url+x, cunurl)
('C:\\Users\\Administrator\\Desktop\\python-test-xiazai\\form_submission.zip', <httplib.HTTPMessage instance at 0x01E25E18>)
('C:\\Users\\Administrator\\Desktop\\python-test-xiazai\\wxDbViewer.zip', <httplib.HTTPMessage instance at 0x01E573A0>)
('C:\\Users\\Administrator\\Desktop\\python-test-xiazai\\wxDnD.zip', <httplib.HTTPMessage instance at 0x01E25D78>)
Type "copyright", "credits" or "license()" for more information.
>>> import urllib2,urllib
>>> url = 'http://blog.pythonlibrary.org/wp-content/uploads/2012/06/'
>>> cunchu='C:\Users\Administrator\Desktop\python-test-xiazai'
>>> req = urllib2.Request(url)
>>> content = urllib2.urlopen(req).read()
>>> import re
>>> match = re.compile(r'(?<=href=["]).*?\.zip(?=["])')
>>> rawlv2 = re.findall(match,content)
>>> print rawlv2
['form_submission.zip', 'wxDbViewer.zip', 'wxDnD.zip']
>>> import os
>>> for x in rawlv2:
cunurl=os.path.join(cunchu,x)
urllib.urlretrieve(url+x, cunurl)
('C:\\Users\\Administrator\\Desktop\\python-test-xiazai\\form_submission.zip', <httplib.HTTPMessage instance at 0x01E25E18>)
('C:\\Users\\Administrator\\Desktop\\python-test-xiazai\\wxDbViewer.zip', <httplib.HTTPMessage instance at 0x01E573A0>)
('C:\\Users\\Administrator\\Desktop\\python-test-xiazai\\wxDnD.zip', <httplib.HTTPMessage instance at 0x01E25D78>)
相关文章推荐
- python 深浅拷贝
- python基础教程第一章知识点记录
- python 入门笔记(三)
- python之小电话薄(功能简陋版)
- 在win10中python3安装opencv3
- 提供给开发者 10 款最好的 Python IDE
- Python 中 import和import...from的区别
- 第一章Python 初步介绍
- python_getopt解析命令行输入参数的使用
- python学习——基础
- python 学习笔记(02)
- 类练习题1:将浮点数转化为金额的类
- python 学习笔记(01)
- Python 日记-1
- Ubuntu14.04 安装配置Opencv3.0和Python2.7
- sublime text2中运行java和python
- python中结巴包的一些东西
- python 装饰器
- python 自动化测试平台 Robot Framework 内置库 翻译
- python PIL模块的下载