Firecrawl へようこそ
使い方
- API: ドキュメント
- SDKs: Python, Node, Go, Rust
- LLMフレームワーク: LangChain (Python), LangChain (JS), LlamaIndex, Crew.ai, Composio, PraisonAI, Superinterface, Vectorize
- ローコードフレームワーク: Dify, Langflow, Flowise AI, Cargo, Pipedream
- その他: Zapier, Pabbly Connect
- SDKやインテグレーションが必要ですか?Issueを作成してお知らせください。
APIキー
クローリング
インストール
pip install firecrawl-py
npm install firecrawl
go get github.com/mendableai/firecrawl-go
# 次を Cargo.toml に追加します
[dependencies]
firecrawl = "^0.1"
tokio = { version = "^1", features = ["full"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
uuid = { version = "^1.10", features = ["v4"] }
[build-dependencies]
tokio = { version = "1", features = ["full"] }
使い方
from firecrawl import Firecrawl
app = Firecrawl(api_key="YOUR_API_KEY")
crawl_result = app.crawl_url('docs.firecrawl.dev', {'crawlerOptions': {'excludes': ['blog/*']}})
# Markdown を取得
for result in crawl_result:
print(result['markdown'])
import { Firecrawl } from "firecrawl";
// API キーで Firecrawl を初期化
const app = new Firecrawl({ apiKey: "YOUR_API_KEY" });
// Web サイトをクロール
const crawlResult = await app.crawlUrl("docs.firecrawl.dev", {
crawlerOptions: { excludes: ["blog/*"] },
});
// Markdown を出力
console.log(crawlResult.map((result) => result.markdown));
import (
"fmt"
"log"
"github.com/mendableai/firecrawl-go"
)
func main() {
// API キーで Firecrawl を初期化
app, err := firecrawl.NewFirecrawlApp("YOUR_API_KEY")
if err != nil {
log.Fatalf("Failed to initialize Firecrawl: %v", err)
}
// Web サイトをクロール
params := map[string]any{
"crawlerOptions": map[string]any{
"excludes": []string{"blog/*"},
},
}
crawlResult, err := app.CrawlURL("docs.firecrawl.dev", params)
if err != nil {
log.Fatalf("Error occurred while crawling: %v", err)
}
// Markdown を取得
for _, result := range crawlResult {
fmt.Println(result.Markdown)
}
}
use firecrawl::Firecrawl;
#[tokio::main]
async fn main() {
// API キーで Firecrawl を初期化
let api_key = "YOUR_API_KEY";
let api_url = "https://api.firecrawl.dev";
let app = Firecrawl::new(api_key, api_url).expect("Failed to initialize Firecrawl");
// URL をクロール
let crawl_params = json!({
"crawlerOptions": {
"excludes": ["blog/*"]
}
});
let crawl_result = app
.crawl_url("https://example.com", Some(crawl_params), true, 2, None)
.await;
// クロール結果を出力
match crawl_result {
Ok(data) => println!("Crawl Result:\n{}", data),
Err(e) => eprintln!("Crawl failed: {}", e),
}
}
curl -X POST https://api.firecrawl.dev/v0/crawl \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"url": "https://docs.firecrawl.dev"
}'
wait_until_done を false に設定できます。
この場合は jobId が返されます。
cURL では、/crawl は常に jobId を返し、それを使ってクロール状況を確認できます。
{ "jobId": "1234-5678-9101" }
クローラー ジョブの確認
status = app.check_crawl_status(job_id)
const status = await app.checkCrawlStatus(jobId);
status, err := app.CheckCrawlStatus(jobId)
if err != nil {
log.Fatalf("Failed to check crawl status: %v", err)
}
let status = match app.check_crawl_status(jobId).await {
Ok(status) => status,
Err(e) => panic!("Failed to check crawl status: {:?}", e),
};
println!("Crawl Status: {:?}", status);
curl -X GET https://api.firecrawl.dev/v0/crawl/status/1234-5678-9101 \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY'
レスポンス
{
"status": "完了",
"current": 22,
"total": 22,
"data": [
{
"content": "生データ",
"markdown": "# Markdownコンテンツ",
"provider": "web-scraper",
"metadata": {
"title": "Firecrawl | LLM向けに信頼性高くウェブをスクレイプ",
"description": "CXと営業向けのAI"
"language": null,
"sourceURL": "https://docs.firecrawl.dev/"
}
}
]
}
スクレイピング
scrape_url メソッドを使用します。URLを引数に取り、スクレイプ結果を辞書 (ディクショナリ) 型で返します。
from firecrawl import Firecrawl
app = Firecrawl(api_key="YOUR_API_KEY")
content = app.scrape_url("https://docs.firecrawl.dev")
import { Firecrawl } from 'firecrawl-js';
const app = new Firecrawl({ apiKey: 'YOUR_API_KEY' });
const content = await app.scrapeUrl('https://docs.firecrawl.dev');
import (
"log"
"github.com/mendableai/firecrawl-go"
)
func main() {
app, err := firecrawl.NewFirecrawlApp("YOUR_API_KEY")
if err != nil {
log.Fatalf("Failed to initialize Firecrawl: %v", err)
}
content, err := app.ScrapeURL("docs.firecrawl.dev", nil)
if err != nil {
log.Fatalf("Failed to scrape URL: %v", err)
}
}
use firecrawl::Firecrawl;
#[tokio::main]
async fn main() {
// APIキーを使用してFirecrawlを初期化
let api_key = "YOUR_API_KEY";
let api_url = "https://api.firecrawl.dev";
let app = Firecrawl::new(api_key, api_url).expect("Failed to initialize Firecrawl");
// URLをスクレイピング
let scrape_result = app.scrape_url("https://example.com", None).await;
// スクレイピング結果を出力
match scrape_result {
Ok(data) => println!("Scrape Result:\n{}", data["markdown"]),
Err(e) => eprintln!("Scrape failed: {}", e),
}
}
curl -X POST https://api.firecrawl.dev/v0/scrape \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"url": "https://docs.firecrawl.dev"
}'
レスポンス
{
"success": true,
"data": {
"markdown": "<文字列>",
"content": "<文字列>",
"html": "<文字列>",
"rawHtml": "<文字列>",
"metadata": {
"title": "<文字列>",
"description": "<文字列>",
"language": "<文字列>",
"sourceURL": "<文字列>",
"<その他のメタデータ>": "<文字列>",
"pageStatusCode": 123,
"pageError": "<文字列>"
},
"llm_extraction": {},
"warning": "<文字列>"
}
}
抽出
class ArticleSchema(BaseModel):
title: str
points: int
by: str
commentsURL: str
class TopArticlesSchema(BaseModel):
top: List[ArticleSchema] = Field(..., max_items=5, description="トップ5の記事")
data = app.scrape_url('https://news.ycombinator.com', {
'extractorOptions': {
'extractionSchema': TopArticlesSchema.model_json_schema(),
'mode': 'llm-extraction'
},
'pageOptions':{
'onlyMainContent': True
}
})
print(data["llm_extraction"])
import { Firecrawl } from "firecrawl";
import { z } from "zod";
const app = new Firecrawl({
apiKey: "fc-YOUR_API_KEY",
});
// 抽出する内容のためのスキーマを定義
const schema = z.object({
top: z
.array(
z.object({
title: z.string(),
points: z.number(),
by: z.string(),
commentsURL: z.string(),
})
)
.length(5)
.describe("Top 5 stories on Hacker News"),
});
const scrapeResult = await app.scrapeUrl("https://news.ycombinator.com", {
extractorOptions: { extractionSchema: schema },
});
console.log(scrapeResult.data["llm_extraction"]);
import (
"fmt"
"log"
"github.com/mendableai/firecrawl-go"
)
app, err := NewFirecrawlApp(TEST_API_KEY, API_URL)
if err != nil {
log.Fatalf("Firecrawl の初期化に失敗しました: %v", err)
}
params := map[string]any{
"extractorOptions": ExtractorOptions{
Mode: "llm-extraction",
ExtractionPrompt: "Based on the information on the page, find what the company's mission is and whether it supports SSO, and whether it is open source",
ExtractionSchema: map[string]any{
"type": "object",
"properties": map[string]any{
"company_mission": map[string]string{"type": "string"},
"supports_sso": map[string]string{"type": "boolean"},
"is_open_source": map[string]string{"type": "boolean"},
},
"required": []string{"company_mission", "supports_sso", "is_open_source"},
},
},
}
scrapeResult, err := app.ScrapeURL("https://news.ycombinator.com", params)
if err != nil {
log.Fatalf("Failed to scrape URL: %v", err)
}
fmt.Println(scrapeResult.LLMExtraction)
use firecrawl::Firecrawl;
#[tokio::main]
async fn main() {
// APIキーを使って Firecrawl を初期化
let api_key = "YOUR_API_KEY";
let api_url = "https://api.firecrawl.dev";
let app = Firecrawl::new(api_key, api_url).expect("Failed to initialize Firecrawl");
// 抽出用のスキーマを定義
let json_schema = json!({
"type": "object",
"properties": {
"top": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"points": {"type": "number"},
"by": {"type": "string"},
"commentsURL": {"type": "string"}
},
"required": ["title", "points", "by", "commentsURL"]
},
"minItems": 5,
"maxItems": 5,
"description": "Top 5 stories on Hacker News"
}
},
"required": ["top"]
});
let llm_extraction_params = json!({
"extractorOptions": {
"extractionSchema": json_schema,
"mode": "llm-extraction"
},
"pageOptions": {
"onlyMainContent": true
}
});
let llm_extraction_result = app
.scrape_url("https://news.ycombinator.com", Some(llm_extraction_params))
.await;
match llm_extraction_result {
Ok(data) => println!("LLM Extraction Result:\n{}", data["llm_extraction"]),
Err(e) => eprintln!("LLM Extraction failed: {}", e),
}
}
curl -X POST https://api.firecrawl.dev/v0/scrape \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"url": "https://docs.firecrawl.dev/",
"extractorOptions": {
"mode": "llm-extraction",
"extractionPrompt": "Based on the information on the page, extract the information from the schema. ",
"extractionSchema": {
"type": "object",
"properties": {
"company_mission": {
"type": "string"
},
"supports_sso": {
"type": "boolean"
},
"is_open_source": {
"type": "boolean"
},
"is_in_yc": {
"type": "boolean"
}
},
"required": [
"company_mission",
"supports_sso",
"is_open_source",
"is_in_yc"
]
}
}
}'

