Python正则表达式练习
爬取慕课课程图片https://www.imooc.com/course/list
图片url
In [13]: import urllib2 In [14]: req = urllib2.urlopen('https://www.imooc.com/course/list') In [17]: listurl = re.findall(r'src=.+//(.+\.jpg)',buf) In [18]: listurl Out[18]: ['img1.mukewang.com/529dc3380001379906000338-240-135.jpg', 'img2.mukewang.com/57035ff200014b8a06000338-240-135.jpg', 'img.mukewang.com/574669dc0001993606000338-240-135.jpg', 'img2.mukewang.com/53e1d0470001ad1e06000338-240-135.jpg', 'img3.mukewang.com/53a28e960001311b06000338-240-135.jpg', 'img3.mukewang.com/540e57300001d6d906000338-240-135.jpg', 'img4.mukewang.com/5b5b00d10001d05205400300-240-135.jpg', 'img1.mukewang.com/5b56e2ab000194d806000338-240-135.jpg', 'img1.mukewang.com/5b55b3f400017b9906000338-240-135.jpg', 'img.mukewang.com/5b4ed6590001d9ee06000338-240-135.jpg', 'img2.mukewang.com/5b4705c90001fc9506000338-240-135.jpg', 'img1.mukewang.com/5b470bfe0001cdbf06000338-240-135.jpg', 'img.mukewang.com/5b4863e40001a8c506000338-240-135.jpg', 'img4.mukewang.com/5b33637d00016cbe05400300-240-135.jpg', 'img3.mukewang.com/5b3dec540001278406000338-240-135.jpg', 'img3.mukewang.com/5b20d7dd000124da06000338-240-135.jpg', 'img3.mukewang.com/5b14f0d3000189d206000338-240-135.jpg', 'img4.mukewang.com/5b39ca9100014d8605400300-240-135.jpg', 'img3.mukewang.com/5b5188020001677306000338-240-135.jpg', 'img2.mukewang.com/5b1e49640001904606000338-240-135.jpg', 'img1.mukewang.com/5b3061210001550306000338-240-135.jpg', 'img3.mukewang.com/5b289bbe0001fc4906000338-240-135.jpg', 'img2.mukewang.com/5b14e8310001197706000338-240-135.jpg', 'img1.mukewang.com/5b28da010001930906000338-240-135.jpg', 'img4.mukewang.com/5b2218750001370806000338-240-135.jpg', 'img4.mukewang.com/5b1f61150001a20905400300-240-135.jpg', 'img.mukewang.com/5b1e0cfc0001ef7b06000338-240-135.jpg', 'img3.mukewang.com/5b1dd1fa0001b70d06000338-240-135.jpg', 'img1.mukewang.com/5b14d44b00014f9606000338-240-135.jpg', 'img4.mukewang.com/5b14b0480001672706000338-240-135.jpg'] In [28]: for url in listurl: f = open(str(i)+'.jpg','w') req = urllib2.urlopen('http://'+url) buf = req.read() f.write(buf) i+=1