MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / Parser

Class Parser

web_programming/emails_from_url.py:26–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class Parser(HTMLParser):
27 def __init__(self, domain: str) -> None:
28 super().__init__()
29 self.urls: list[str] = []
30 self.domain = domain
31
32 def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
33 """
34 This function parse html to take takes url from tags
35 """
36 # Only parse the 'anchor' tag.
37 if tag == "a":
38 # Check the list of defined attributes.
39 for name, value in attrs:
40 # If href is defined, not empty nor # print it and not already in urls.
41 if name == "href" and value not in (*self.urls, "", "#"):
42 url = parse.urljoin(self.domain, value)
43 self.urls.append(url)
44
45
46# Get main domain name (example.com)

Callers 1

emails_from_urlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected