实操2
Chapter 1 - 基础形态
1.1 - Basic Type
import asyncio
from crawl4ai import AsyncWebCrawler
import os
OUTPUT_PATH = './outputs/markdown/'
def output_md(base_filename, md_str):
os.makedirs(OUTPUT_PATH, exist_ok=True)
length = len(md_str)
name, ext = os.path.splitext(base_filename)
filename = f"{name}({length}){ext}"
full_path = os.path.join(OUTPUT_PATH, filename)
with open(full_path, 'w', encoding='utf-8') as f:
f.write(md_str)
print(f"已保存到: {full_path}")
async def main(output_filename):
async with AsyncWebCrawler() as crawler:
result = await crawler.arun("https://www.anthropic.com/news/agent-capabilities-api")
print("Markdown length:", len(result.markdown))
print(result.markdown[:300])
output_md(output_filename, result.markdown)
asyncio.run(main('1_1_Basic.md'))
PS E:\AI-lab\n8n> & D:/anaconda3/envs/crawl4ai-python311/python.exe e:/AI-lab/n8n/crawl4ai-1.py
[INIT].... → Crawl4AI 0.6.3
[FETCH]... ↓ https://www.anthropic.com/news/agent-capabilities-api | ✓ | ⏱: 3.40s
[SCRAPE].. ◆ https://www.anthropic.com/news/agent-capabilities-api | ✓ | ⏱: 0.03s
[COMPLETE] ● https://www.anthropic.com/news/agent-capabilities-api | ✓ | ⏱: 3.43s
Markdown length: 10941
[Skip to main content](https://www.anthropic.com/news/agent-capabilities-api
[](https://www.anthropic.com/)
* Claude
* API
* Solutions
* Research
* Commitments
* Learn
[News](https://www.anthropic
已保存到: ./outputs/markdown/1_1_Basic(10941).md