Skip to main content

Scraper

Struct Scraper 

Source
pub struct Scraper { /* private fields */ }

Implementations§

Source§

impl Scraper

Source

pub async fn map(&self, req: &MapRequest) -> Result<Vec<MapLink>, ApiError>

Source

pub async fn crawl( &self, req: &CrawlRequest, sink: Arc<dyn CrawlSink>, ) -> Result<(), ApiError>

整站爬取。深度按发现顺序计算:起始页和 sitemap 里的页面是 0。 带 query 时按相关性优先调度(见 crate::focus),否则广度优先。

Source§

impl Scraper

Source

pub async fn observe( &self, url: &str, instruction: &str, ) -> Result<(Vec<Value>, LlmUse), ApiError>

observe:页面上和指令对应的候选元素(选择器、角色、名称),最合适的在前。

Source§

impl Scraper

Source

pub async fn search(&self, req: &SearchRequest) -> Result<Value, ApiError>

Source

pub async fn extract(&self, req: &ExtractRequest) -> Result<Value, ApiError>

Source§

impl Scraper

Source

pub fn builder(config: ScraperConfig) -> ScraperBuilder

Source

pub fn hooks(&self) -> &Hooks

输出阶段的钩子由写结果的一方调用:Rust 用户在自己写结果的地方调;内置入口里只有 CLI 的 crawl 调用。

Source§

impl Scraper

Source

pub async fn act( &self, url: &str, instruction: &str, text: Option<&str>, ) -> Result<(Document, Value), ApiError>

0.97 的 act:在真实页面上选一个元素,点击它;给了 text 时输入(text 不发给模型也不进缓存, 其中的 {{secret:NAME}} 在本地换成配置的值)。选元素走计划缓存,同一类页面、同一句话不再问模型。 返回执行后的页面,页面随即关闭。

Source§

impl Scraper

Source

pub async fn scrape_session( &self, url: &str, opts: &ScrapeOptions, keep: bool, owner: Option<&str>, ) -> Result<Document, ApiError>

/v2/scrape:keep 时保留页面;否则只记下回放信息。结果带 metadata.scrapeId。

Source

pub async fn interact( &self, id: &str, req: &InteractRequest, owner: Option<&str>, ) -> Result<InteractResponse, ApiError>

Source

pub async fn stop_interact( &self, id: &str, owner: Option<&str>, ) -> Result<InteractStopped, ApiError>

Source§

impl Scraper

Source

pub async fn parse( &self, upload: Upload, opts: &ScrapeOptions, ) -> Result<Document, ApiError>

解析上传的文件并写审计记录(kind: parse)。不存快照:上传的文件往往不公开。

Source§

impl Scraper

Source

pub fn new(config: ScraperConfig) -> Result<Self, ScraperError>

Source

pub async fn probe_engines(&self) -> Vec<EngineProbe>

把内核链里的每个内核真的启动一次,逐个给出结果(doctor 用):文件在不等于能启动, 启动即崩的兜底内核要说出来。

Source

pub async fn probe_browsers(&self)

服务启动时在后台把每个内核启动一次,确认哪些能用(日志里写明),能用的浏览器留着备用。

Source

pub async fn shutdown(&self)

Source

pub async fn scrape( &self, url: &str, opts: &ScrapeOptions, ) -> Result<Document, ApiError>

Source

pub fn audit_robots_ignored( &self, kind: RequestKind, mode: RobotsMode, url: &str, )

整站爬取或 map 实际忽略了 robots.txt 时写一条审计记录(没配置审计日志时什么都不做)。

Source

pub fn audit(&self) -> Option<&Arc<Audit>>

审计日志(没配置时为 None)。

Source

pub fn llm_client(&self) -> Option<&ChatClient>

配置的 LLM 客户端(多服务器网关跑 agent 时用)。

配了搜索后端。

Source

pub fn policy(&self) -> &Policy

Source

pub fn route_pages(&self, runner: Arc<dyn PageRunner>) -> bool

网关模式:此后爬取里的页面交给 runner 执行(只能设一次,之后的调用返回 false)。

Source

pub fn page_runner(&self) -> Option<&Arc<dyn PageRunner>>

Source

pub fn planner(&self) -> &RenderPlanner

渲染决策的计数表(多服务器工人上报统计、导入网关下发的先验用)。

Source

pub fn learner(&self) -> &HostLearner

Source

pub fn engine_count(&self) -> usize

内核链的长度(换内核决策的族按内核序号区分)。

Source

pub fn network_stage_snapshots(&self) -> Vec<StageSnapshot>

Source

pub fn transport_phase_snapshots(&self) -> Vec<PhaseSnapshot>

Source

pub fn crawl_slots(&self) -> &AdaptiveConcurrencyGate

Source

pub fn concurrency(&self) -> usize

当前的全局并发目标(限速器的 USL 控制器给出,冷启动等于配置的全局并发)。

多服务器网关上页面由工人执行:取在线工人报告的准入容量之和(至少 1), 爬取的在途上限和名额闸门都跟着它走。单主机没有装执行方,路径不变。

Source

pub fn observe_crawl(&self, _queue_wait: Duration, _failed: bool)

爬取里一页结束。并发目标由限速器在名额归还时按观测窗更新(事件驱动), 这里只把爬取闸门的上限同步过去;取代 0.81 每秒采样一次的运行时调优器。

Source

pub async fn scrape_with( &self, url: &str, opts: &ScrapeOptions, mode: RobotsMode, ) -> Result<Document, ApiError>

按给定的 robots 模式抓一页;整站爬取和 map 用它,robots 模式由调用方按请求类型决定。 先查缓存(语义同 Firecrawl 的 maxAge、minAge、storeInCache),没命中再抓取并写入。 queryFilter、LLM 格式和 changeTracking 都在缓存之外、基于正文 Markdown 做, 缓存里存的总是完整正文。

Source

pub async fn scrape_audited( &self, kind: &str, url: &str, opts: &ScrapeOptions, mode: RobotsMode, ) -> Result<Document, ApiError>

抓一页并写审计记录。kind 区分单页抓取和爬取里的页面。

Source§

impl Scraper

Source

pub async fn find_similar( &self, url: &str, selector: &str, opts: &ScrapeOptions, ) -> Result<SimilarData, ApiError>

selector 取第一个命中的元素当例子;opts 要包含 rawHtml 格式。

Trait Implementations§

Source§

impl Engine for Scraper

Source§

fn supports_actions(&self) -> bool

动作只在 Chrome 上验证过,和 interact 同一个条件。

Source§

fn admitted_concurrency(&self) -> Option<usize>

统一准入:批量任务的并发取当前全局在途数目标(限速器的 USL 控制器)。

Source§

fn scrape<'a>( &'a self, url: &'a str, opts: &'a ScrapeOptions, ) -> BoxFuture<'a, Result<Document, ApiError>>

Source§

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 校验。
Source§

fn map<'a>( &'a self, req: &'a MapRequest, ) -> BoxFuture<'a, Result<Vec<MapLink>, ApiError>>

Source§

fn crawl<'a>( &'a self, req: &'a CrawlRequest, sink: Arc<dyn CrawlSink>, ) -> BoxFuture<'a, Result<(), ApiError>>

整站爬取:抓到一页、出错一页、发现新 URL 时都通过 sink 回报,直到爬完或被取消。
Source§

fn search<'a>( &'a self, req: &'a SearchRequest, ) -> BoxFuture<'a, Result<Value, ApiError>>

/v2/search:返回 Firecrawl 的 data({ "web": [...] })。
Source§

fn extract<'a>( &'a self, req: &'a ExtractRequest, ) -> BoxFuture<'a, Result<Value, ApiError>>

/v2/extract:返回提取出的 JSON。
Source§

fn supports_interact(&self) -> bool

是否支持 /v2/scrape/{id}/interact。支持时 /v2/scrape 走 Engine::scrape_session。
Source§

fn actions_unavailable(&self) -> &'static str

不支持 actions 时给调用方的说明。
Source§

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 只认同一个账号。
Source§

fn observe<'a>( &'a self, url: &'a str, instruction: &'a str, ) -> BoxFuture<'a, Result<Observed, ApiError>>

/v2/observe:页面上和指令对应的候选元素(选择器、角色、名称),返回候选和用量警告。
Source§

fn find_similar<'a>( &'a self, url: &'a str, selector: &'a str, opts: &'a ScrapeOptions, ) -> BoxFuture<'a, Result<SimilarData, ApiError>>

/v2/similar:和例子结构相同的兄弟元素。
Source§

fn interact<'a>( &'a self, id: &'a str, req: &'a InteractRequest, owner: Option<&'a str>, ) -> BoxFuture<'a, Result<InteractResponse, ApiError>>

Source§

fn stop_interact<'a>( &'a self, id: &'a str, owner: Option<&'a str>, ) -> BoxFuture<'a, Result<InteractStopped, ApiError>>

Source§

fn agent_check(&self, req: &AgentRequest) -> Result<(), ApiError>

/v2/agent 开跑前的检查:没配 LLM、没有 urls 又没配搜索时,提交时就报错。
Source§

fn agent<'a>( &'a self, req: &'a AgentRequest, sink: Arc<dyn AgentSink>, ) -> BoxFuture<'a, AgentOutcome>

/v2/agent:跑完一次(中途出错也回已经攒下的证据,错误在 AgentOutcome::error)。
Source§

fn supported_formats(&self) -> &'static [&'static str]

引擎支持的 formats;请求了不支持的格式时返回 UNSUPPORTED_OPTION,不悄悄忽略。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more