1.主要用到了urllib和re库 html
2.利用urllib.urlopen()函数得到页面源代码 函数
3.利用正则匹配图片类型,固然正则越准确,下载的越多 学习
4.利用urllib.urlretrieve()下载图片,而且能够从新命名,利用%S url
5.应该是运营商有所限制,因此未能下载所有的图片,不过仍是OK的spa
URL分析:code
源码:htm
#coding=utf-8 import re import urllib def getHtml(url): page=urllib.urlopen(url) html=page.read(); return html def getImage(html): reg=r'src="(.*?\.jpg)" size' imgre=re.compile(reg) imgeList =re.findall(imgre,html) x=0 for image in imgeList: urllib.urlretrieve(image,'%s_hhh.jpg' % x) x+=1 html=getHtml("https://tieba.baidu.com/p/5256641773") getImage(html)