-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from zzstoatzz/no-excerpt
allow skipping excerpting
- Loading branch information
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# /// script | ||
# dependencies = [ | ||
# "raggy", | ||
# "trafilatura", | ||
# ] | ||
# /// | ||
|
||
import asyncio | ||
|
||
from bs4 import BeautifulSoup | ||
|
||
import raggy | ||
from raggy.loaders.web import SitemapLoader | ||
|
||
|
||
def html_parser(html: str) -> str: | ||
import trafilatura | ||
|
||
trafilatura_config = trafilatura.settings.use_config() # type: ignore | ||
trafilatura_config.set("DEFAULT", "EXTRACTION_TIMEOUT", "0") | ||
return ( | ||
trafilatura.extract(html, config=trafilatura_config) | ||
or BeautifulSoup(html, "html.parser").get_text() | ||
) | ||
|
||
|
||
async def main(urls: list[str]): | ||
raggy.settings.html_parser = html_parser | ||
loader = SitemapLoader(urls=urls, create_excerpts=False) | ||
docs = await loader.load() | ||
print(f"scraped {len(docs)} documents") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main(["https://prefect.io/blog/sitemap.xml"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters