1花履、根據(jù)給定的網(wǎng)址獲取網(wǎng)頁(yè)源代碼
2、利用正則表達(dá)式把源代碼中的圖片地址過(guò)濾出來(lái)
3、根據(jù)過(guò)濾出來(lái)的圖片地址下載網(wǎng)絡(luò)圖片
#coding:utf-8
import urllib
import re
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html):
reg = r'src="(.+?\.jpg)" pic_ext'
image = re.compile(reg)
imglist = image.findall(html)
x = 0
for imgurl in imglist:
urllib.urlretrieve(imgurl,'%s.jpg' % x)
x = x + 1
html = getHtml("[http://tieba.baidu.com/p/2460150866](http://tieba.baidu.com/p/2460150866)")
getImg(html)