Python爬取百度贴吧图片脚本
2017-02-20 11:00
190 查看
新手,以下是爬取百度贴吧制定帖子的图片脚本,因为脚本主要是解析html代码,因此一旦百度修改页面前端代码,那么脚本会失效,权当爬虫入门练习吧,后续还会尝试更多的爬虫。
# coding=utf-8 # !/usr/bin/env python import urllib, string, os from bs4 import BeautifulSoup def getHtml(url): page = urllib.urlopen(url) html = page.read() return html def getImg(): imgPath = 'F:/craw_tieba/' if not os.path.exists(imgPath): os.makedirs(imgPath) baseUrl = 'http://tieba.baidu.com/p/4657665666' imgList = [] for pg in range(1, 114): url = baseUrl + '?pn=' + str(pg) print 'Craw: ',url html = getHtml(url) soup = BeautifulSoup(html) imgURLList = string.split(str(soup.find_all('img')), ',') for i in range(0, len(imgURLList)): if 'http://imgsrc.baidu.com/forum/w%3D580/sign=' in imgURLList[i]: start = string.find(imgURLList[i], 'http') end = string.find(imgURLList[i], '.jpg') + 4 imgList.append(imgURLList[i][start : end]) x = 1 for img in imgList: urllib.urlretrieve(img, 'F:/craw_tieba/%s.jpg' % x) x += 1 print 'Craw tieba finish!' if __name__ == '__main__': getImg()
相关文章推荐
- python脚本爬取百度贴吧里的图片并下载到指定路径下,支持多页同时下载
- python爬取百度贴吧图片
- 【Python3.6爬虫学习记录】(四)爬取百度贴吧某帖子内容及图片
- 使用Python脚本将文字转换为图片的实例分享
- 可用于获取百度贴吧的帖子中的Email地址的Python脚本
- python:爬取百度贴吧图片
- Python爬虫--抓取百度贴吧图片
- 使用Python3编写抓取网页和只抓网页图片的脚本
- 使用Python3编写抓取网页和只抓网页图片的脚本
- Python爬虫_简单获取百度贴吧图片
- 用Python爬取百度贴吧中的图片
- 第一个Python3.0 爬虫程序, 爬取百度贴吧图片
- python爬虫:下载百度贴吧图片(多页)学习笔记
- Python--爬取一个百度贴吧的图片(风景吧)
- Ukulele百度贴吧图片python3单线程爬取
- Python爬虫学习记录(1)——百度贴吧图片下载
- python 批量更换图片格式脚本
- python抓取百度贴吧高清图片
- EarthLiveSharp中cloudinary的CDN图片缓存自动清理python脚本
- python3.x百度贴吧图片爬虫(附知乎图片爬虫)