Files
python/python爬虫/crawl4ai/02_基础配置.py
T
2025-08-05 09:19:34 +08:00

21 lines
598 B
Python

import asyncio
from crawl4ai import AsyncWebCrawler, BrowserConfig, CrawlerRunConfig, CacheMode
async def main():
browser_conf = BrowserConfig(headless=True) # 设为 False 以观察浏览器
run_conf = CrawlerRunConfig(
cache_mode=CacheMode.BYPASS # 此处为获取最新内容,默认为 CacheMode.ENABLED
)
async with AsyncWebCrawler(config=browser_conf) as crawler:
result = await crawler.arun(
url="https://example.com",
config=run_conf
)
print(result.markdown)
if __name__ == "__main__":
asyncio.run(main())