Detect HTML Tags, Attributes and Attribute Values

Sort by

recency

|

149 Discussions

|

  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print (tag)
            if attrs:
                for attr, value in attrs:
                    print(f"-> {attr} > {value}")
    
    
    html = ""       
    for i in range(int(input())):
        html += input().rstrip()
        html += '\n'
        
    parser = MyHTMLParser()
    parser.feed(html)
    parser.close()
    
  • + 0 comments
    from html.parser import HTMLParser
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print(tag)
            for x, y in attrs:
                print(f"-> {x} > {y}")
    t = ''.join(input() for _ in range(int(input())))
    parser = MyHTMLParser()
    parser.feed(t)
    
  • + 0 comments

    This chall is too similar from html parsing 1 2 3 . Nothing new to learn .

  • + 1 comment
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            print(tag)
            if attrs:
                [print(f'-> {attr[0]} > {attr[1]}') for attr in attrs]
        def handle_startendtag(self, tag, attrs):
            print(tag)
            if attrs:
                [print(f'-> {attr[0]} > {attr[1]}') for attr in attrs]  
      
    html = ""       
    for _ in range(int(input())):
        html += input().rstrip()
        html += '\n'
        
    parser = MyHTMLParser()
    parser.feed(html)
    parser.close()
    
  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, att):
            print(tag)
            self.print_atributes(att)
        def print_atributes(self, att):
            for name, val in att:
                print(f'-> {name} > {val}')
            
    
    parser = MyHTMLParser()
    for _ in range(int(input())):
        parser.feed(input())