python获取某网址下所有图片
2014-04-30 15:53
99 查看
import urllib import urllib.request import re def get_save(url,picname): response=urllib.request.urlopen(url) data=response.read() f=open(picname,'wb') f.write(data) f.close() def get_all_picurl(url): #write the html to file response=urllib.request.urlopen(url) data=response.read() f=open('C:\\xx.txt','wb') f.write(data) f.close() #read to data and extract the img url f=open('c:\\xx.txt','r',encoding='utf-8') data=f.read() pattern = re.compile(r'src="(data/attachment/forum/.{20,40}\.jpg)') result = re.findall(pattern,data,0) f.close() return result url_header='http://bbs.chinanews.com/' url_first_page='http://bbs.chinanews.com/picview-185-4977929-1.shtml#' picurls=get_all_picurl(url_first_page) count=0 for a_url in picurls: count+=1 print('processing'+' '+str(count)+":"+a_url+'...'+'\n') url_pic=url_header+a_url name_pic='C:\\Users\\Administrator\\Desktop\\chinanews\\'+str(count)+'.jpg' get_save(url_pic,name_pic)
相关文章推荐
- uwsgi1.9.17的python开发环境配置
- Python安装、配置图文详解(转载)
- 【机器学习算法-python实现】svm支持向量机(1)—理论知识介绍
- Python启程
- python笔记之列表和元组
- 五、Python学习之 logging 模块
- PythonChallenge闯关游戏——第16-20关
- 关于一次小工作的总结,python解压缩,过滤文本
- python的序列化和反序列化
- Python如何安装模块
- Python学习笔记(7)Mouse Input, More Lists and Dictionaries
- Python+正则表达式,简单爬下我博客的信息
- Python学习笔记(6)List and Keyboard Control
- python中机器学习包scikit-learn使用笔记与sign prediction简单小结
- python中文字符编码decode,encode以及乱码解决总结
- 【Python】windows下Eclipse中安装集成webpy框架
- PythonChallenge闯关游戏——第11-15关
- 一个简单的界面,使用wxpython
- [leetcode]Reorder List @ Python
- 用Python作流场计算时的后处理问题