diff options
Diffstat (limited to 'R2R/r2r/parsers/text/html_parser.py')
-rwxr-xr-x | R2R/r2r/parsers/text/html_parser.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/R2R/r2r/parsers/text/html_parser.py b/R2R/r2r/parsers/text/html_parser.py new file mode 100755 index 00000000..9c663fbe --- /dev/null +++ b/R2R/r2r/parsers/text/html_parser.py @@ -0,0 +1,15 @@ +from typing import AsyncGenerator + +from bs4 import BeautifulSoup + +from r2r.base.abstractions.document import DataType +from r2r.base.parsers.base_parser import AsyncParser + + +class HTMLParser(AsyncParser[DataType]): + """A parser for HTML data.""" + + async def ingest(self, data: DataType) -> AsyncGenerator[str, None]: + """Ingest HTML data and yield text.""" + soup = BeautifulSoup(data, "html.parser") + yield soup.get_text() |