代码:
import urllib2 import re req = urllib2.urlopen('https://www.imooc.com/course/list') buf = req.read() image_link = re.findall(r'//img.+\.(?:jpg|png)',buf) print image_link print len(image_link) i = 0 for url in image_link: print url f = open(str(i)+'.jpg','w') req = urllib2.urlopen('http:'+url) buf = req.read() f.write(buf) i+=1
下载图片共42张,大部分效果如下:
打开方式用wb试一下