From c70cab386df2d91a1f7c64d85e5b3f1d2198dcd2 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 9 Oct 2021 14:02:20 +0200 Subject: [PATCH] hypertext --- hypertext.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 hypertext.py diff --git a/hypertext.py b/hypertext.py new file mode 100644 index 0000000..44abffd --- /dev/null +++ b/hypertext.py @@ -0,0 +1,18 @@ +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