Python学习 之 爬虫
2015-06-22 21:18
573 查看
目标:下载贴吧或空间中所有图片
步骤:(1)获取页面代码 (2)获取图片URL,下载图片
代码如下:
步骤:(1)获取页面代码 (2)获取图片URL,下载图片
代码如下:
#!/usr/bin/python import re import urllib def getHtml(url): page=urllib.urlopen(url) html=page.read() return html def getImg(html): reg=r'src="(.*?\.jpg)" width' imgre=re.compile(reg) imglist=re.findall(imgre,html) x=0 for imgurl in imglist: urllib.urlretrieve(imgurl,'%s.jpg' % x) x+=1 html=getHtml("http://tieba.baidu.com/p/749901827?fr=good") getImg(html)
相关文章推荐
- (翻译)如何对python dict 类型按键(keys)或值(values)排序
- python bottle框架使用beaker支持session
- python 连接mysql多层结构实例
- Python学习 之 正则表达式
- Python运算符及表达式
- python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样
- Python简单对文件进行读写操作
- python 微信企业号
- python-基础教程笔记
- install python+twisted+mysqldb+django on mac
- Python套接字编程(1)——socket模块与套接字编程
- 学习《Python核心编程》做一下知识点提要,方便复习(一)
- python unicode转str方法
- Python学习手册 上传文件太大,上传2次均失败
- alex教学用例--员工信息表
- Python学习 之 包和模块
- Python装饰器
- Python学习 之 内建函数
- Python上下文管理器
- Python描述器