前言¶
DeepSeek Harness(DSH)采用插件化架构,把能力开放给开发者。但在编写智能体时,常遇到两个问题:一是缺乏面向模型的抓取接口,二是想把成熟的 Python 抓取库(如 Scrapling)嵌入 DSH 却没有现成集成方案。dsh-scrapling 插件通过一个 Python 桥接进程,把 Scrapling 的抓取能力暴露为 4 个工具(fetch / extract / batch / site),供模型侧直接调用。
这是什么¶
dsh-scrapling 是一个 DSH 插件,由 tietoumiao 维护,分类为「联网工具」。它把 Scrapling 的能力封装成四个模型可用的工具:scrape_fetch、scrape_extract、scrape_batch、scrape_site。插件以 MIT 许可发布,不包含 Scrapling 源码,仅通过子进程调用。
核心功能¶
scrape_fetch:将一个 URL 抓取为 markdown / 纯文本 / 原始 HTML,附带状态码、跳转后 URL、标题、字符数与截断标记,支持 GET / POST。scrape_extract:通过 CSS/XPath 或::text提取具名字段,或以rows模式提取列表/表格为对象集合。scrape_batch:最多 50 个 URL 并发抓取,单 URL 失败不影响整体,可对每个 URL 执行提取。scrape_site:基于 ContentSpider 爬站,一页一条 markdown,受max_pages与总字符预算约束。
两档引擎:
http(默认):伪装 HTTP 客户端(curl_cffi 指纹),不启动浏览器,约 2~3.5 秒。stealth:真浏览器(StealthyFetcher),可运行 JS、带反检测、可过 Cloudflare Turnstile,冷启动约 5~10 秒。
安装与启用¶
需要 DSH 宿主、Python 3.10+ 与已安装 Scrapling:
pip install "scrapling[fetchers]"
把本仓库放入 DSH 可加载的插件目录,并在 profile 的 dsh.profile.bundles 里登记插件 id。配置示例:
- insert:
- id: dsh-scrapling
name: dsh-scrapling
config:
python: '/path/to/python' # 已装 scrapling 的解释器
root: '/path/to/scrapling-root' # 存放 .sessions / .tmp / browsers
callTimeoutMs: 120000
maxChars: 20000
典型用法¶
// 抓一页正文
await scrape_fetch({ url: "https://example.com", format: "markdown" })
// 列表 → 一组对象
await scrape_extract({
url: "https://news.ycombinator.com",
rows: { container: ".athing", limit: 30, fields: {
title: { selector: ".titleline a" },
href: { selector: ".titleline a", attribute: "href" },
rank: { selector: ".rank", regex: "(\\d+)" }
}}
})
// 过 Cloudflare
await scrape_fetch({ url: "...", mode: "stealth", options: { solve_cloudflare: true } })
适用场景与注意¶
适合需要在智能体中直接使用抓取能力的场景,如新闻聚合、信息抽取、站点监控等。插件以当前 DSH 进程的权限运行,安装前应检查源码与许可证。
短结尾¶
dsh-scrapling 通过四个工具将 Scrapling 能力接入模型侧,提供从单页抓取到站点爬取的统一接口。更多细节与源码见目录页与 GitHub 仓库。