Sort by

recency

|

176 Discussions

|

  • + 0 comments

    Here is HackerRank HTML Parser - Part 1 in Python solution - https://programmingoneonone.com/hackerrank-html-parser-part-1-solution-in-python.html

  • + 0 comments
    1. from html.parser import HTMLParser
      1. class MyHTMLParser(HTMLParser):
    2. def handle_starttag(self , tag , attrs):
    3. print("Start :",tag)
    4. for name,value in attrs:
    5. print(f"-> {name} > {value}")
      1. def handle_endtag(self,tag):
    6. print("End :", tag)
      1. def handle_startendtag(self,tag,attrs):
    7. print("Empty :",tag)
    8. for name,value in attrs:
    9. print(f"-> {name} > {value}")
      1. parser = MyHTMLParser()
    10. for i in range(int(input())):
    11. parser.feed(input())
  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs):
            if attrs:
                print(f"Start : {tag}")
                for attr in attrs:
                    attr_name = attr[0]
                    attr_value = attr[1] if len(attr) > 1 else None
                    print(f"-> {attr_name} > {attr_value}")
            else:
                print(f"Start : {tag}")
    
        def handle_endtag(self, tag):
            print(f"End   : {tag}")
    
        def handle_startendtag(self, tag, attrs):
            if attrs:
                print(f"Empty : {tag}")
                for attr in attrs:
                    attr_name = attr[0]
                    attr_value = attr[1] if len(attr) > 1 else None
                    print(f"-> {attr_name} > {attr_value}")
            else:
                print(f"Empty : {tag}")
    
        def handle_comment(self, data):
            pass
            
    parser = MyHTMLParser()
    N = int(input())
    
    html_code = '\n'.join([input() for _ in range(N)])
    parser.feed(html_code)
    
  • + 1 comment

    Can I just say, This is a perfect example of why everyone in industry thinks Software Devs have autism...

    The description provided for this task is absolutely appaling...

    Huges pieces of key information missing, assumptions made all over the bloody place. no "Hey, extend this class and implement these new methods, here's how the feed method will class these new classes, etc"...

    Nope, ignore all that shit... lmfao

  • + 0 comments
    from html.parser import HTMLParser
    
    class MyHTMLParser(HTMLParser):
        def handle_starttag(self, tag, attrs ):
            print('Start :',tag)
            for attr in attrs:
                print(f"-> {attr[0]} > {attr[1] if attr[1] else 'None'}")
                
        def handle_endtag(self, tag):
            print('End   :', tag)
            
        def handle_startendtag(self, tag, attrs ):
            print('Empty :', tag)
            for attr in attrs:
                print(f"-> {attr[0]} > {attr[1] if attr[1] else 'None'}")
        
    N = int(input())
    
    html_code = '\n'.join([input() for _ in range(N)])
    
    parser = MyHTMLParser()
    parser.feed(html_code)