Skip to main content

Crate pagesift

Crate pagesift 

Source
Expand description

pagesift:把网页变成给大模型用的干净 Markdown。

这个 crate 既是库也是命令行工具。库的入口是 Scraper:

let scraper = pagesift::Scraper::new(pagesift::ScraperConfig::default())?;
let doc = scraper.scrape("https://example.com", &Default::default()).await?;
println!("{}", doc.markdown.unwrap_or_default());

Re-exports§

pub use pagesift_api as api;
pub use pagesift_hooks as hooks;
pub use pagesift_store as store;

Modules§

audit
审计日志:每次抓取写一行 JSON(只有元数据),结果可疑时另存当时的 HTML,供事后复现。
cluster
多服务器部署的接线:把 pagesift-cluster 的协调器接到 HTTP 服务和 crate::Scraper 上。
collect
Incremental JSON API collection with page checkpoints and acknowledged events. A source must have one writer and a stable, authoritative listing to enable deletion. Delivery is at least once; destinations must deduplicate events.
config
配置(PRD 6.11):pagesift.toml,路径由 --config 或 PAGESIFT_CONFIG 指定。 优先级:命令行参数 > 环境变量 > 配置文件 > 默认值。
download
Identity-addressed, bounded, resumable file archive. This is a downloader, not a site-extractor library. One advisory lock protects each archive root.
mcp
MCP 工具:把 pagesift-mcp 定义的工具接到真正的抓取引擎上。 crawl 和 batch scrape 复用 API 层的任务管理,pagesift_poll_job 两种任务都能查, pagesift_cancel_job 两种任务都能停。 配置了审计日志时多一个 pagesift_report_issue,让调用方把看到的错误结果记下来。
media
Explicit media protocol adapters. An adapter is selected by the caller; unknown sites never silently fall back to scraping arbitrary JSON URLs.
models
下载模型:从上游的锁定版本下载,边下边校验大小和 SHA-256,校验过才放到最终位置。走 pagesift-net,遵守代理等网络设置。权重不随本仓库分发。
notice
哪些 warning 要让调用方直接看到:结果可能不完整、不对,或者根本不是想要的页面。
postprocess
Deterministic filenames and recoverable binary + metadata publication. The sidecar is the commit marker, published last; this is not a two-file atomic FS.
scripts
Opt-in, origin-scoped external module traversal. Candidates carry provenance and remain separate from observed browser traffic or confirmed GET requests.
session
Explicit on-disk ownership for an HTTP session. Persistence is opt-in and the caller saves after requests; no hidden shared cookie file or automatic identity swap.
stream
Native bounded HLS/DASH VOD planning. Unsupported live/encrypted/index-based formats fail explicitly. Planning does not execute a player or a helper tool.

Structs§

EngineProbe
内核链里一个内核的启动检查结果(Scraper::probe_engines)。
InteractLimits
保留会话的时长上限。
Scraper
ScraperBuilder
Scraper::builder(config).hook(...):在代码里注册钩子(和 [[rules]] 编译出的放在同一组链里)。
ScraperConfig

Enums§

ScraperError
创建 Scraper 失败:网络层或 LLM 客户端的配置不对。

Constants§

AUTO_RENDER_ARTICLE_MIN_CHARS
已经认出是一篇文章(有发布时间或 og:type=article)时,正文到这么多加权字符就不再渲染: 短新闻 HTTP 已经拿全了。AiSeek 的生产数据里,63% 的渲染拿到的文字和 HTTP 一样多, 多半就是这类短文章。
AUTO_RENDER_MIN_CHARS
F-1.9:HTTP 抓到的正文少于这么多(加权)字符时,engine: auto 升级到浏览器渲染。 中日韩文字一个字按 CJK_WEIGHT 个字符算(信息量和几个拉丁字母相当),见 text_weight。

Traits§

PageRunner
爬取里逐页抓取的执行者。网关把它装到 Scraper 上(engine::Scraper::route_pages), 爬取前沿留在网关,页面交给工人。

Functions§

needs_render
engine: auto 时 HTTP 的结果是否还要用浏览器渲染。
normalize_url
URL 规范化(F-6.2),用来去重:去掉 fragment;查询参数排序,或者整个去掉。 协议和主机的小写、默认端口、.. 路径由 URL 解析本身处理。
office_markdown
把一份 Office/EPUB/CSV 文档转成 Markdown,供引擎和评测共用。deadline 到了报超时。 CSV 的字符集按正文探测;知道 Content-Type 时用 office_markdown_from。
office_markdown_from
同 office_markdown,另给文件来源的 Content-Type(响应头或上传时的):CSV 按它的 charset 解码,和网页一样;声明和正文对不上时纠正并给 decode: 警告。
set_cpu_capacity
进程可用的 CPU 数,由建运行时的一方在绑核之前设置。
set_cpu_groups
CPU 工人的分组:每个 NUMA 节点允许使用的逻辑 CPU。设置后工人按组分配、绑到所在组的 CPU 集, 偷任务先在组内偷(0.70 在 192 vCPU 上的实测,见 pagesift_flow::cpu)。 不设置时(Python、Node 宿主)工人不绑核。
text_weight
正文的加权长度:空白不算,中日韩文字按 CJK_WEIGHT 算。