メインコンテンツへスキップ

前提条件

クレートをインストール

Cargo.tomlfirecrawl を追加します:
[dependencies]
firecrawl = "1"
tokio = { version = "1", features = ["full"] }
serde_json = "1"
reqwest = { version = "0.12", features = ["json"] }

ウェブを検索

use firecrawl::v2::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new("fc-YOUR-API-KEY")?;
    let results = client.search("firecrawl web scraping", None).await?;

    for result in &results {
        println!("{} - {}", result.title.as_deref().unwrap_or(""), result.url.as_deref().unwrap_or(""));
    }
    Ok(())
}

ページをスクレイピングする

let doc = client.scrape("https://example.com", None).await?;
println!("{}", doc.markdown.unwrap_or_default());
{
  "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
  "metadata": {
    "title": "Example Domain",
    "sourceURL": "https://example.com"
  }
}

ページを操作する

Interact API は、HTTP 経由でプロンプトベースのコマンドを使用します。ページをスクレイピングして scrapeId を取得し、その後プロンプトを送信してブラウザセッションを操作します:
use reqwest::Client as HttpClient;
use serde_json::json;

let api_key = "fc-YOUR-API-KEY";
let http = HttpClient::new();

// 1. ブラウザセッションを開くためにスクレイピング
let scrape_res: serde_json::Value = http
    .post("https://api.firecrawl.dev/v2/scrape")
    .bearer_auth(api_key)
    .json(&json!({ "url": "https://www.amazon.com", "formats": ["markdown"] }))
    .send().await?
    .json().await?;

let scrape_id = scrape_res["data"]["metadata"]["scrapeId"]
    .as_str().unwrap();

// 2. 操作するためにプロンプトを送信
http.post(format!("https://api.firecrawl.dev/v2/scrape/{scrape_id}/interact"))
    .bearer_auth(api_key)
    .json(&json!({ "prompt": "Search for iPhone 16 Pro Max" }))
    .send().await?;

let interact_res: serde_json::Value = http
    .post(format!("https://api.firecrawl.dev/v2/scrape/{scrape_id}/interact"))
    .bearer_auth(api_key)
    .json(&json!({ "prompt": "Click on the first result and tell me the price" }))
    .send().await?
    .json().await?;

println!("{}", interact_res);

// 3. セッションを閉じる
http.delete(format!("https://api.firecrawl.dev/v2/scrape/{scrape_id}/interact"))
    .bearer_auth(api_key)
    .send().await?;

環境変数

キーを直接渡す代わりに、FIRECRAWL_API_KEY を設定してください。
export FIRECRAWL_API_KEY=fc-YOUR-API-KEY
firecrawl クレートは、FirecrawlApp を通じて v1 API にも対応しています。利用可能な API 全体については、Rust SDK docs を参照してください。

次のステップ

Search のドキュメント

Web を検索して、ページ全体のコンテンツを取得

Scrape のドキュメント

フォーマット、アクション、プロキシを含む、すべてのスクレイピングのオプション

Interact のドキュメント

クリック、フォーム入力、動的コンテンツの抽出

Rust SDK リファレンス

クロール、map などを含む SDK リファレンス