当前位置: 移动技术网 > IT编程>脚本编程>Python > python获取糗百图片代码实例

python获取糗百图片代码实例

2019年04月02日  | 移动技术网IT编程  | 我要评论

苹果全集,疯狂猜成语一心投篮,as956.tk

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网