源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

python获取糗百图片代码实例

  • 时间:2020-06-29 16:41 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python获取糗百图片代码实例
[u]复制代码[/u] 代码如下:
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()
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部