mrmp/hypertext.py
Marc Beninca c70cab386d hypertext
2023-01-28 21:19:16 +01:00

18 lines
397 B
Python

import html.parser
class Parser(html.parser.HTMLParser):
def __init__(self):
self.links = []
super().__init__()
def handle_starttag(self, tag, attributes):
if tag == 'a':
self.links.extend(
[v for k, v in attributes if k == 'href'])
def get_links(hypertext):
parser = Parser()
parser.feed(hypertext)
return parser.links