crawl4ai/docs/examples/hello_world.py

34 lines
997 B
Python
Raw Normal View History

import asyncio
from crawl4ai import (
AsyncWebCrawler,
BrowserConfig,
CrawlerRunConfig,
CacheMode,
DefaultMarkdownGenerator,
PruningContentFilter,
CrawlResult
)
2025-01-13 19:19:58 +08:00
async def main():
browser_config = BrowserConfig(headless=True, verbose=True)
async with AsyncWebCrawler(config=browser_config) as crawler:
crawler_config = CrawlerRunConfig(
cache_mode=CacheMode.BYPASS,
markdown_generator=DefaultMarkdownGenerator(
2025-01-13 19:19:58 +08:00
content_filter=PruningContentFilter(
threshold=0.48, threshold_type="fixed", min_word_threshold=0
)
),
)
result : CrawlResult = await crawler.arun(
# url="https://www.helloworld.org", config=crawler_config
url="https://www.kidocode.com", config=crawler_config
)
print(result.markdown_v2.raw_markdown[:500])
# print(result.model_dump())
2025-01-13 19:19:58 +08:00
if __name__ == "__main__":
2025-01-13 19:19:58 +08:00
asyncio.run(main())