mrmp/hypertext.py

23 lines
491 B
Python
Raw Normal View History

2021-10-09 12:02:20 +00:00
import html.parser
2021-10-10 00:40:21 +00:00
import requests
CHARSET = 'u8'
2021-10-09 12:02:20 +00:00
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'])
2021-10-10 00:40:21 +00:00
def get_links(location):
hypertext = requests.get(location).content.decode(CHARSET)
2021-10-09 12:02:20 +00:00
parser = Parser()
parser.feed(hypertext)
return parser.links