Python第一个爬虫(爬取贴吧图片)
2017-09-28 14:11
330 查看
Python第一个爬虫(爬取贴吧图片)
1.导入的包
# coding:utf-8 import urllib2,urllib import re
2.使用urllib2打开页面读取数据
def getHtml(url): page = urllib2.urlopen(url) html = page.read() return html
3.使用正则表达式,解析数据,获取想要的数据
def getImg(html): reg = r'murl":"(.+?)"' imgre = re.compile(reg) imgList = re.findall(imgre,html) x=0; for imgUrl in imgList: print imgUrl urllib.urlretrieve(imgUrl,'C:\Users\xxx\Desktop\ss\%s.jpg'%x)//调用方法下载图片 x+=1
4.调用方法,爬取贴吧的图片
html = getHtml("http://tieba.baidu.com/photo/g/bw/picture/list?kw=%E5%9B%BE%E7%89%87&alt=jview&rn=200&tid=1433290786&pn=1&ps=1&pe=40&info=1&_=1506576344661&red_tag=b1600243292") getImg(html)
##运行截图
##结果截图
结束
相关文章推荐
- Python爬虫学习:我的第一个爬虫—爬取贴吧感兴趣帖子的图片(大家都懂,哈哈)
- 用Python 爬虫爬取贴吧图片
- python 实现一个贴吧图片爬虫的示例
- 第一个python程序,小爬虫--抓取网页图片
- 第一个Python3.0 爬虫程序, 爬取百度贴吧图片
- 使用Python3批量保存贴吧图片-附爬虫程序
- python爬虫爬去贴吧中的所有图片
- [python爬虫]爬取贴吧某页美女图片+爬取糗百美女图片
- [Python爬虫]爬取贴吧图片
- 用Python 爬虫爬取贴吧图片
- 使用Python爬虫爬取贴吧图片数据
- 纪念我的第一个Python爬虫——图片
- Python爬虫__爬取贴吧图片和文本
- Python爬虫入门——爬取贴吧图片
- [python] 第一个爬虫, 爬妹子写真集图片
- 我的第一个python爬虫程序(从百度贴吧自动下载图片)
- Python爬虫入门——爬取贴吧图片
- Python3爬虫入门之贴吧图片批量获取
- Python-贴吧图片爬虫
- 使用Python写的第一个网络爬虫程序