> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firecrawl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust

> RustでFirecrawlを始めましょう。公式SDKを使用して、ウェブデータを検索し、スクレイピングし、Interactできます。

<div id="prerequisites">
  ## 前提条件
</div>

* Cargo が使える Rust 1.70 以降
* Firecrawl APIキー — [無料で取得する](https://www.firecrawl.dev/app/api-keys)

<div id="install-the-crate">
  ## クレートをインストール
</div>

`Cargo.toml` に `firecrawl` を追加します:

```toml theme={null}
[dependencies]
firecrawl = "2"
tokio = { version = "1", features = ["full"] }
serde_json = "1"
```

<div id="search-the-web">
  ## ウェブを検索
</div>

```rust theme={null}
use firecrawl::{Client, SearchOptions};

#[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",
        SearchOptions { limit: Some(5), ..Default::default() },
    ).await?;

    if let Some(web) = results.data.web {
        for item in web {
            if let firecrawl::SearchResultOrDocument::WebResult(r) = item {
                println!("{} - {}", r.url, r.title.unwrap_or_default());
            }
        }
    }
    Ok(())
}
```

<div id="scrape-a-page">
  ## ページをスクレイピングする
</div>

```rust theme={null}
let doc = client.scrape("https://example.com", None).await?;
println!("{}", doc.markdown.unwrap_or_default());
```

<Accordion title="レスポンス例">
  ```json theme={null}
  {
    "markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
    "metadata": {
      "title": "Example Domain",
      "sourceURL": "https://example.com"
    }
  }
  ```
</Accordion>

<div id="interact-with-a-page">
  ## ページをInteractする
</div>

ページをスクレイピングして `scrapeId` を取得し、Interact API を使ってブラウザセッションを操作します:

```rust theme={null}
use firecrawl::{Client, ScrapeOptions, Format, ScrapeExecuteOptions};

let doc = client.scrape(
    "https://www.amazon.com",
    ScrapeOptions {
        formats: Some(vec![Format::Markdown]),
        ..Default::default()
    },
).await?;

let scrape_id = doc.metadata
    .as_ref()
    .and_then(|m| m.scrape_id.as_deref())
    .expect("scrapeId not found");

// ページを操作するプロンプトを送信する
let run = client.interact(
    scrape_id,
    ScrapeExecuteOptions {
        prompt: Some("Search for iPhone 16 Pro Max".to_string()),
        ..Default::default()
    },
).await?;

let run = client.interact(
    scrape_id,
    ScrapeExecuteOptions {
        prompt: Some("Click on the first result and tell me the price".to_string()),
        ..Default::default()
    },
).await?;

println!("{:?}", run.output);

// セッションを閉じる
client.stop_interaction(scrape_id).await?;
```

<div id="environment-variable">
  ## 環境変数
</div>

キーを直接渡す代わりに、`FIRECRAWL_API_KEY` を設定してください。

```bash theme={null}
export FIRECRAWL_API_KEY=fc-YOUR-API-KEY
```

```rust theme={null}
let api_key = std::env::var("FIRECRAWL_API_KEY")?;
let client = Client::new(api_key)?;
```

<div id="next-steps">
  ## 次のステップ
</div>

<CardGroup cols={2}>
  <Card title="Search のドキュメント" icon="magnifying-glass" href="/ja/features/search">
    Web を検索して、ページ全体のコンテンツを取得
  </Card>

  <Card title="スクレイピング のドキュメント" icon="file-lines" href="/ja/features/scrape">
    フォーマット、アクション、プロキシを含む、すべてのスクレイピングのオプション
  </Card>

  <Card title="Interact のドキュメント" icon="hand-pointer" href="/ja/features/interact">
    クリック、フォーム入力、動的コンテンツの抽出
  </Card>

  <Card title="Rust SDK リファレンス" icon="rust" href="/ja/sdks/rust">
    クロール、map、バッチスクレイプ などを含む SDK リファレンス
  </Card>
</CardGroup>
