记录一段用HTMLParser解析html的python代码:

data = urllib.urlopen('http://10.85.40.153').read()

#data = response.read()
print data

class parseHtml(HTMLParser.HTMLParser):
    def handle_starttag(self, tag, attrs):
        print tag
        if 'input'.__contains__(tag):
            for name, value in attrs:
                print 'name=%s,value=%s' % (name, value)
                if value.__contains__('Home'):
                    print value
                    print self.get_starttag_text()



parse = parseHtml()
parse.feed(data)

Python:HTMLParser,解析html

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.