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()

本文python获取糗百图片代码实例到此结束。不停站,想开往地老天荒需要多勇敢,人生无常,时不我待。小编再次感谢大家对我们的支持!

标签: 百图 python