mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-18 02:32:04 -05:00
Restructuring the Repo to make it clear the difference between classic autogpt and the autogpt platform: * Move the "classic" projects `autogpt`, `forge`, `frontend`, and `benchmark` into a `classic` folder * Also rename `autogpt` to `original_autogpt` for absolute clarity * Rename `rnd/` to `autogpt_platform/` * `rnd/autogpt_builder` -> `autogpt_platform/frontend` * `rnd/autogpt_server` -> `autogpt_platform/backend` * Adjust any paths accordingly
34 lines
937 B
Python
34 lines
937 B
Python
"""HTML processing functions"""
|
|
from __future__ import annotations
|
|
|
|
from bs4 import BeautifulSoup
|
|
from requests.compat import urljoin
|
|
|
|
|
|
def extract_hyperlinks(soup: BeautifulSoup, base_url: str) -> list[tuple[str, str]]:
|
|
"""Extract hyperlinks from a BeautifulSoup object
|
|
|
|
Args:
|
|
soup (BeautifulSoup): The BeautifulSoup object
|
|
base_url (str): The base URL
|
|
|
|
Returns:
|
|
List[Tuple[str, str]]: The extracted hyperlinks
|
|
"""
|
|
return [
|
|
(link.text, urljoin(base_url, link["href"]))
|
|
for link in soup.find_all("a", href=True)
|
|
]
|
|
|
|
|
|
def format_hyperlinks(hyperlinks: list[tuple[str, str]]) -> list[str]:
|
|
"""Format hyperlinks to be displayed to the user
|
|
|
|
Args:
|
|
hyperlinks (List[Tuple[str, str]]): The hyperlinks to format
|
|
|
|
Returns:
|
|
List[str]: The formatted hyperlinks
|
|
"""
|
|
return [f"{link_text.strip()} ({link_url})" for link_text, link_url in hyperlinks]
|