码迷,mamicode.com
首页 > 其他好文 > 详细

煎蛋 无聊图解析

时间:2015-02-13 16:28:39      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

import requests
from html.parser import HTMLParser

class MyHtmlParser(HTMLParser):
    srclist = {}
    count = 0
    def handle_starttag(self, tag, attrs):
        if tag == img:
            #print("Encountered a start tag:", tag)
            for x in attrs:
                if x[0] in (src,org_src) and x[1].find(jandan) == -1:
                    #print(x[1].find(‘jandan‘),x[1])
                    self.srclist[self.count] = x[1]
            self.count += 1
    def handle_endtag(self, tag):
        if tag == img:
            pass
            #print("Encountered an end tag:", tag)
    def handle_data(self, data):
        pass
        #print("Encountered some data:", data)
for x in range(4000,6002):
    iurl = http://jandan.net/pic/page-+str(x)
    r = requests.get(iurl)
    parser = MyHtmlParser()
    parser.feed(str(r.content))
    for k, v in parser.srclist.items():
        print(v)

 

煎蛋 无聊图解析

标签:

原文地址:http://www.cnblogs.com/yumuxu/p/4290311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!