pub trait Engine:
Send
+ Sync
+ 'static {
Show 18 methods
// Required method
fn scrape<'a>(
&'a self,
url: &'a str,
opts: &'a ScrapeOptions,
) -> BoxFuture<'a, Result<Document, ApiError>>;
// Provided methods
fn parse<'a>(
&'a self,
_file: Upload,
_opts: &'a ScrapeOptions,
) -> BoxFuture<'a, Result<Document, ApiError>> { ... }
fn map<'a>(
&'a self,
_req: &'a MapRequest,
) -> BoxFuture<'a, Result<Vec<MapLink>, ApiError>> { ... }
fn crawl<'a>(
&'a self,
_req: &'a CrawlRequest,
_sink: Arc<dyn CrawlSink>,
) -> BoxFuture<'a, Result<(), ApiError>> { ... }
fn search<'a>(
&'a self,
_req: &'a SearchRequest,
) -> BoxFuture<'a, Result<Value, ApiError>> { ... }
fn extract<'a>(
&'a self,
_req: &'a ExtractRequest,
) -> BoxFuture<'a, Result<Value, ApiError>> { ... }
fn agent_check(&self, _req: &AgentRequest) -> Result<(), ApiError> { ... }
fn agent<'a>(
&'a self,
_req: &'a AgentRequest,
_sink: Arc<dyn AgentSink>,
) -> BoxFuture<'a, AgentOutcome> { ... }
fn supported_formats(&self) -> &'static [&'static str] { ... }
fn supports_actions(&self) -> bool { ... }
fn actions_unavailable(&self) -> &'static str { ... }
fn supports_interact(&self) -> bool { ... }
fn scrape_session<'a>(
&'a self,
_url: &'a str,
_opts: &'a ScrapeOptions,
_keep: bool,
_owner: Option<&'a str>,
) -> BoxFuture<'a, Result<Document, ApiError>> { ... }
fn observe<'a>(
&'a self,
_url: &'a str,
_instruction: &'a str,
) -> BoxFuture<'a, Result<Observed, ApiError>> { ... }
fn find_similar<'a>(
&'a self,
_url: &'a str,
_selector: &'a str,
_opts: &'a ScrapeOptions,
) -> BoxFuture<'a, Result<SimilarData, ApiError>> { ... }
fn interact<'a>(
&'a self,
_id: &'a str,
_req: &'a InteractRequest,
_owner: Option<&'a str>,
) -> BoxFuture<'a, Result<InteractResponse, ApiError>> { ... }
fn stop_interact<'a>(
&'a self,
_id: &'a str,
_owner: Option<&'a str>,
) -> BoxFuture<'a, Result<InteractStopped, ApiError>> { ... }
fn admitted_concurrency(&self) -> Option<usize> { ... }
}Required Methods§
fn scrape<'a>( &'a self, url: &'a str, opts: &'a ScrapeOptions, ) -> BoxFuture<'a, Result<Document, ApiError>>
Provided Methods§
Sourcefn parse<'a>(
&'a self,
_file: Upload,
_opts: &'a ScrapeOptions,
) -> BoxFuture<'a, Result<Document, ApiError>>
fn parse<'a>( &'a self, _file: Upload, _opts: &'a ScrapeOptions, ) -> BoxFuture<'a, Result<Document, ApiError>>
/v2/parse:解析调用方上传的文件(PDF、HTML),返回和 scrape 相同的文档。
opts 已经过 crate::check_parse_options 校验。
fn map<'a>( &'a self, _req: &'a MapRequest, ) -> BoxFuture<'a, Result<Vec<MapLink>, ApiError>>
Sourcefn crawl<'a>(
&'a self,
_req: &'a CrawlRequest,
_sink: Arc<dyn CrawlSink>,
) -> BoxFuture<'a, Result<(), ApiError>>
fn crawl<'a>( &'a self, _req: &'a CrawlRequest, _sink: Arc<dyn CrawlSink>, ) -> BoxFuture<'a, Result<(), ApiError>>
整站爬取:抓到一页、出错一页、发现新 URL 时都通过 sink 回报,直到爬完或被取消。
Sourcefn search<'a>(
&'a self,
_req: &'a SearchRequest,
) -> BoxFuture<'a, Result<Value, ApiError>>
fn search<'a>( &'a self, _req: &'a SearchRequest, ) -> BoxFuture<'a, Result<Value, ApiError>>
/v2/search:返回 Firecrawl 的 data({ "web": [...] })。
Sourcefn extract<'a>(
&'a self,
_req: &'a ExtractRequest,
) -> BoxFuture<'a, Result<Value, ApiError>>
fn extract<'a>( &'a self, _req: &'a ExtractRequest, ) -> BoxFuture<'a, Result<Value, ApiError>>
/v2/extract:返回提取出的 JSON。
Sourcefn agent_check(&self, _req: &AgentRequest) -> Result<(), ApiError>
fn agent_check(&self, _req: &AgentRequest) -> Result<(), ApiError>
/v2/agent 开跑前的检查:没配 LLM、没有 urls 又没配搜索时,提交时就报错。
Sourcefn agent<'a>(
&'a self,
_req: &'a AgentRequest,
_sink: Arc<dyn AgentSink>,
) -> BoxFuture<'a, AgentOutcome>
fn agent<'a>( &'a self, _req: &'a AgentRequest, _sink: Arc<dyn AgentSink>, ) -> BoxFuture<'a, AgentOutcome>
/v2/agent:跑完一次(中途出错也回已经攒下的证据,错误在 AgentOutcome::error)。
Sourcefn supported_formats(&self) -> &'static [&'static str]
fn supported_formats(&self) -> &'static [&'static str]
引擎支持的 formats;请求了不支持的格式时返回 UNSUPPORTED_OPTION,不悄悄忽略。
Sourcefn supports_actions(&self) -> bool
fn supports_actions(&self) -> bool
是否支持 actions(需要浏览器渲染)。
不支持 actions 时给调用方的说明。
Sourcefn supports_interact(&self) -> bool
fn supports_interact(&self) -> bool
是否支持 /v2/scrape/{id}/interact。支持时 /v2/scrape 走 Engine::scrape_session。
Sourcefn scrape_session<'a>(
&'a self,
_url: &'a str,
_opts: &'a ScrapeOptions,
_keep: bool,
_owner: Option<&'a str>,
) -> BoxFuture<'a, Result<Document, ApiError>>
fn scrape_session<'a>( &'a self, _url: &'a str, _opts: &'a ScrapeOptions, _keep: bool, _owner: Option<&'a str>, ) -> BoxFuture<'a, Result<Document, ApiError>>
/v2/scrape:抓一页,结果带 metadata.scrapeId。keep 时保留浏览器页面(keepSession),
否则只记下回放信息。owner 是调用方的账号,之后的 interact 只认同一个账号。
Sourcefn observe<'a>(
&'a self,
_url: &'a str,
_instruction: &'a str,
) -> BoxFuture<'a, Result<Observed, ApiError>>
fn observe<'a>( &'a self, _url: &'a str, _instruction: &'a str, ) -> BoxFuture<'a, Result<Observed, ApiError>>
/v2/observe:页面上和指令对应的候选元素(选择器、角色、名称),返回候选和用量警告。
Sourcefn find_similar<'a>(
&'a self,
_url: &'a str,
_selector: &'a str,
_opts: &'a ScrapeOptions,
) -> BoxFuture<'a, Result<SimilarData, ApiError>>
fn find_similar<'a>( &'a self, _url: &'a str, _selector: &'a str, _opts: &'a ScrapeOptions, ) -> BoxFuture<'a, Result<SimilarData, ApiError>>
/v2/similar:和例子结构相同的兄弟元素。
fn interact<'a>( &'a self, _id: &'a str, _req: &'a InteractRequest, _owner: Option<&'a str>, ) -> BoxFuture<'a, Result<InteractResponse, ApiError>>
fn stop_interact<'a>( &'a self, _id: &'a str, _owner: Option<&'a str>, ) -> BoxFuture<'a, Result<InteractStopped, ApiError>>
Sourcefn admitted_concurrency(&self) -> Option<usize>
fn admitted_concurrency(&self) -> Option<usize>
统一准入现在允许的在途抓取数:批量任务的并发按它定,用户的
max_batch_concurrency 只作上限。引擎还没接准入时返回 None,API 用配置或先验。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".