Python爬虫网页图片
来源:互联网 发布:office mac中缺失字体 编辑:程序博客网 时间:2024/05/18 07:29
python环境2.7
今天是学习python第二天,做了一个抓取网页图片的爬虫。代码很简练。
#coding=utf-8import urllibimport redef getHtml(url): page = urllib.urlopen(url) html = page.read() return htmldef getImg(html): reg = r'src="(.+?\.jpg)" size=' imgre = re.compile(reg) imglist = re.findall(imgre,html) x = 0 for imgurl in imglist: urllib.urlretrieve(imgurl,'%s.jpg' % x) x+=1 return imglisthtml = getHtml("https://tieba.baidu.com/p/5052815069")print getImg(html)
其中getHtml()是由地址获取类文件对象,然后通过正则表达式提取我们需要的图片下载链接。下边是循环保存图片,权威解释看知识库吧O(∩_∩)O~
下边是运行截图
下边是成功截图:
0 0
- Python网页图片爬虫
- Python爬虫网页图片
- Python爬虫抓取网页图片
- python 爬虫获取网页图片
- Python 爬虫:获取网页图片
- Python爬虫抓取网页图片
- python网络爬虫,抓取网页图片
- [python][爬虫]从网页中下载图片
- python 爬虫入门1 网页图片保存
- python 爬虫 获取网页中的图片
- 爬虫抓取网页图片
- 爬虫抓取网页图片
- python 网页爬虫+保存图片+多线程+网络代理
- python 网页爬虫+保存图片+多线程+网络代理
- [python爬虫]如何爬取特定网页的图片
- Python爬虫——爬取网页中的图片小试牛刀
- python爬虫之抓取网页中的图片到本地
- Python爬虫学习笔记一:简单网页图片抓取
- Hibernate(8)Stucts+Hibernate+接口编程
- Android 使用 TraceView 分析卡顿问题
- Android Studio调试打包签名设置
- POJ 3254 (基础 状态压缩 DP )
- 前后端分离设计
- Python爬虫网页图片
- Linux下打包压缩war和解压war包
- Android两个EditText互相监听
- SIM逻辑模型与APDU
- 09 操作符重载
- Oracle查询任意时间段内的所有日期,无需建表
- 制定直线方程式和多项式方程式并显示:Django + js + highcharts
- 1093. Count PAT's 解析
- 备份数据库脚本_MySQL