您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

python获取糗百图片代码实例

2025/9/17 12:27:52发布16次查看
代码如下:
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()
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product