#!/usr/bin/python
-*- coding: UTF-8 -*-
import re
import urllib.request
def getHtml(url):
page=urllib.request.urlopen(url)
html=page.read()
return html
html=getHtml("http://tieba.baidu.com/p/3205263090")
html=html.decode('UTF-8')
def getImg(html):
reg=r'src="(.+?.jpg)"pic_ext'
imgre=re.compile(reg)
imgList=re.findall(imgre,html)
return imgList
imgList=getImg(html)
imgName=0
for imgPath in imgList:
f=open("F:/pic/"+str(imgName)+".jpg",'wb')
f.write((urllib.request.urlopen(imgPath)).read())
f.close()
imgName+=1
print("all done")
代码如上,在f盘的pic文件夹下找不到图片。