hypertext
This commit is contained in:
parent
ec871e1081
commit
c70cab386d
1 changed files with 18 additions and 0 deletions
18
hypertext.py
Normal file
18
hypertext.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue