Discuss / Python / 感觉有点笨的办法

感觉有点笨的办法

Topic source

A22B9S

#1 Created at ... [Delete] [Delete and Lock User]

from html.parser import HTMLParser

from html.entities import name2codepoint

switch = 0

class MyHTMLParser(HTMLParser):

    def handle_starttag(self, tag, attrs):

        global switch

        if attrs == [('class', 'list-recent-events menu')]:

            switch = 1

    def handle_endtag(self, tag):

        global switch

        if tag == 'ul':

            if switch == 1:

                switch = 0

    def handle_data(self, data):

        global switch

        if switch == 1:

            print(data)


  • 1

Reply