Crawl4AIは、LLM、AIエージェント、およびデータパイプライン向けに特別に設計された、高速でAI対応のウェブクローラーです。完全にオープンソースで柔軟性があり、リアルタイムパフォーマンスのために構築されており、開発者に比類のない速度、精度、およびデプロイの容易さを提供します。
pip install -U crawl4ai
crawl4ai-setup
crawl4ai-doctor
docker pull unclecode/crawl4ai:0.6.0-rN
docker run -d -p 11235:11235 --name crawl4ai --shm-size=1g unclecode/crawl4ai:0.6.0-rN
# webUI:http://localhost:11235/playground
import asyncio
from crawl4ai import *
async def main():
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(
url="https://www.nbcnews.com/business",
)
print(result.markdown)
if __name__ == "__main__":
asyncio.run(main())
crwl https://www.nbcnews.com/business -o markdown
crwl https://docs.crawl4ai.com --deep-crawl bfs --max-pages 10
crwl https://www.example.com/products -q "Extract all product prices"
import os
import asyncio
from crawl4ai import AsyncWebCrawler, BrowserConfig, CrawlerRunConfig, CacheMode, LLMConfig
from crawl4ai.extraction_strategy import LLMExtractionStrategy
from pydantic import BaseModel, Field
class OpenAIModelFee(BaseModel):
model_name: str = Field(..., description="Name of the OpenAI model.")
input_fee: str = Field(..., description="Fee for input token for the OpenAI model.")
output_fee: str = Field(..., description="Fee for output token for the OpenAI model.")
async def main():
browser_config = BrowserConfig(verbose=True)
run_config = CrawlerRunConfig(
word_count_threshold=1,
extraction_strategy=LLMExtractionStrategy(
llm_config = LLMConfig(provider="openai/gpt-4o", api_token=os.getenv('OPENAI_API_KEY')),
schema=OpenAIModelFee.schema(),
extraction_type="schema",
instruction="""From the crawled content, extract all mentioned model names along with their fees for input and output tokens.
Do not miss any models in the entire content. One extracted model JSON format should look like this:
{"model_name": "GPT-4", "input_fee": "US$10.00 / 1M tokens", "output_fee": "US$30.00 / 1M tokens"}."""
),
cache_mode=CacheMode.BYPASS,
)
async with AsyncWebCrawler(config=browser_config) as crawler:
result = await crawler.arun(
url='https://openai.com/api/pricing/',
config=run_config
)
print(result.extracted_content)
if __name__ == "__main__":
asyncio.run(main())
地理位置、言語、タイムゾーンを設定して、実際の地域固有のコンテンツを取得:
run_config = CrawlerRunConfig(
url="https://browserleaks.com/geo",
locale="en-US",
timezone_id="America/Los_Angeles",
geolocation=GeolocationConfig(
latitude=34.0522,
longitude=-118.2437,
accuracy=10.0,
)
)
HTMLテーブルをCSVまたはpandas DataFrameとして直接抽出:
results = await crawler.arun(
url="https://coinmarketcap.com/?page=1",
config=crawl_config
)
raw_df = pd.DataFrame()
for result in results:
if result.success and result.media["tables"]:
raw_df = pd.DataFrame(
result.media["tables"][0]["rows"],
columns=result.media["tables"][0]["headers"],
)
break
ページ起動時にウォームアップされたブラウザインスタンスを使用し、遅延とメモリ使用量を削減
モデルコンテキストプロトコルを介して、Claude CodeなどのAIツールに接続:
claude mcp add --transport sse c4ai-sse http://localhost:11235/mcp/sse
Crawl4AIには活発なオープンソースコミュニティサポートがあり、コードの貢献、問題の報告、および提案を歓迎します。プロジェクトはApache 2.0ライセンスに従い、完全にオープンソースで無料で使用できます。
Crawl4AIは、特にAI時代の背景において、ウェブクローリング技術の最新の進歩を代表しています。従来のクローラのすべての機能を提供するだけでなく、最新のAIアプリケーション向けに特別に最適化されており、データサイエンティスト、AI研究者、および開発者にとって理想的な選択肢となっています。そのオープンソースの特性と活発なコミュニティを通じて、Crawl4AIはウェブデータ抽出技術の民主化と標準化を推進しています。