import re
import urllib.request
def getHtml(url):
page = urllib.request.urlopen(url)
html = page.read()
return html.decode('gbk', 'ignore')
def getImg(html):
reg = r'src="(.*?\.jpg)" width'
imgre = re.compile(reg)
imglist = imgre.findall(html)
#return imglist
x = 0
for imgurl in imglist:
print(imgurl)
urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
x+=1
else:
print("ending")
html = getHtml("http://www.zcool.com.cn/")
print (getImg(html))
python 3.x网络爬虫 下载图片
最新推荐文章于 2024-04-18 18:23:14 发布