Creates a node for a tree using the given ID which corresponds to a URL. If the parent_id is None, this will be considered a root node.
(self, id: str, parent_id: str | None)
| 44 | self._build_tree(url=self._url, depth=self._depth) |
| 45 | |
| 46 | def _append_node(self, id: str, parent_id: str | None) -> None: |
| 47 | """ |
| 48 | Creates a node for a tree using the given ID which corresponds to a URL. |
| 49 | If the parent_id is None, this will be considered a root node. |
| 50 | """ |
| 51 | resp = self._client.get(id) |
| 52 | soup = BeautifulSoup(resp.text, 'html.parser') |
| 53 | title = soup.title.text.strip() if soup.title is not None else parse_hostname(id) |
| 54 | try: |
| 55 | [classification, accuracy] = classify(resp.text) |
| 56 | numbers = parse_phone_numbers(soup) |
| 57 | emails = parse_emails(soup) |
| 58 | data = LinkNode(title, id, resp.status_code, classification, accuracy, numbers, emails) |
| 59 | self.create_node(title, identifier=id, parent=parent_id, data=data) |
| 60 | except exceptions.DuplicatedNodeIdError: |
| 61 | logging.debug(f"found a duplicate URL {id}") |
| 62 | |
| 63 | def _build_tree(self, url: str, depth: int) -> None: |
| 64 | """ |
no test coverage detected