Rust
Get started with Firecrawl in Rust. Search, scrape, and interact with web data using the official SDK.
Prerequisites
- Rust 1.70+ with Cargo
- A Firecrawl API key — get one free
Install the crate
Add firecrawl to your Cargo.toml:
[dependencies]
firecrawl = "2"
tokio = { version = "1", features = ["full"] }
serde_json = "1"Search the web
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(())
}Scrape a page
let doc = client.scrape("https://example.com", None).await?;
println!("{}", doc.markdown.unwrap_or_default());Interact with a page
Scrape a page to get a scrapeId, then use the interact API to control the browser session:
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");
// Send a prompt to interact with the page
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);
// Close the session
client.stop_interaction(scrape_id).await?;Environment variable
Set FIRECRAWL_API_KEY instead of passing the key directly:
export FIRECRAWL_API_KEY=fc-YOUR-API-KEYlet api_key = std::env::var("FIRECRAWL_API_KEY")?;
let client = Client::new(api_key)?;Next steps
Was this page helpful?Suggest editsRaise issue