python获取糗百图片代码实例
代码如下:
from sgmllib import SGMLParser import urllib2 class sgm(SGMLParser): def reset(self): SGMLParser.reset(self) self.srcs=[] self.ISTRUE=True def start_div(self,artts): for k,v in artts: if v=="author": self.ISTRUE=False def end_div(self): self.ISTRUE=True def start_img(self,artts): for k,v in artts: if k=="src" and self.ISTRUE==True: self.srcs.append(v) def download(self): for src in self.srcs: f=open(src[-12:],"wb") print src img=urllib2.urlopen(src) f.write(img.read()) f.close() sgm=sgm() for page in range(1,500): url="http://www.qiushibaike.com/late/page/%s?s=4622726" % page data=urllib2.urlopen(url).read() sgm.feed(data) sgm.download()
相关推荐
FlySky 2020-11-02
逍遥友 2020-10-26
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02
葫芦小金刚 2020-07-28
StevenSun空间 2020-07-26