来自:https://www.cnblogs.com/xdd1997/p/11962969.html
import re import urllib import urllib.request def getHtml(url): page = urllib.request.urlopen(url) html = page.read() return html def getImage(html,x): #https://mmbiz.qpic.cn/mmbiz_jpg/ib55rg6wzUc3B16KIY3uU53nkcTTDic8uEA4WWBPaHJ8LpibvAnkpS2FZtyjrv7w7dbEeNrhfvPuuyReNAxsLdgJA/640?wx_fmt=jpeg #https://mmbiz.qpic.cn/mmbiz_jpg/ib55rg6wzUc3B16KIY3uU53nkcTTDic8uEHqocI7r86nehl2NeForAqvcTiaEAIuWjTWPKNXnnXIPuUuqnuJeFKYw/640?wx_fmt=jpeg #此处正则为重点 reg = 'data-src="(.*?)"' image = re.compile(reg) imlist = re.findall(reg,html.decode('utf-8')) print(imlist) for i in imlist: print(i) print(x) urllib.request.urlretrieve(i,'%s.jpg' % x) x +=1 return x x=1 url = 'https://mp.weixin.qq.com/s/MVDcn0O3093OlIhMYkqBIA' html = getHtml(url) x = getImage(html,x) print('下载完成') #下载结果与此.py文件在同一目录