Python script to scrape titles of public Youtube playlist
Well, how you handle the output of the titles can be improved. You don't need to fall back to using global variables here. They are very rarely really needed. Here it would be easier to make handle_starttag a generator, which is then consumed by str.join:

class MyHTMLParser(HTMLParser):

    def handle_starttag(self, tag, attrs):
        for attr in attrs:
            if attr[0] == "data-title":
                yield attr[1]

parser = MyHTMLParser()
titles = '\n'.join(parser.feed(html))
print(titles)


This assumes that HTMLParser.feed does not return any other values except from within the handle_starttag method (and that it actually returns the output of handle_starttag).

Note that I increased the number of spaces to 4 per indentation level, as recommended by Python's official style-guide, PEP8.

You also might want to add an early exit if the tag is not the correct tag.



If those assumptions above about feed are wrong, you might want to look for a different tool. Most parsing is done with BeautifulSoup, as far as I can tell. It offers strainers, with which you can reduce the amount of HTML to parse to only those tags you care about and CSS selectors which would let you directly select all of those tags with the right attribute.