SuperAPI AI 工具集

scrapling

数据与分析

查看项目

更新于 10-16 07:23

技能介绍

用途:Scrapling 是网页抓取框架,用于抓取静态 HTML、JS 渲染页面、绕过 Cloudflare Turnstile 或机器人检测,以及用爬虫框架抓取多页站点。当内置 web_extract 工具无法返回所需数据时也可使用。仅限教育与研究用途,使用者须遵守当地及国际数据抓取法律和网站服务条款。

主要能力:提供三种抓取策略——HTTP(Fetcher/FetcherSession,适合静态页、API、快速批量请求)、动态(DynamicFetcher/DynamicSession,适合 JS 渲染内容与 SPA)、隐身(StealthyFetcher/StealthySession,适合 Cloudflare 与反爬站点);另有 Spider 框架支持多页爬取与链接跟随。选择器支持 CSS、XPath、find_all、find_by_text、find_by_regex 及 find_similar。输出格式由文件扩展名决定:.html 原始 HTML、.md Markdown、.txt 纯文本、.json/.jsonl JSON。

使用方式:安装 pip install "scrapling[all]" 后运行 scrapling install;仅 HTTP 用 pip install scrapling;仅浏览器自动化用 pip install "scrapling[fetchers]" 后运行 scrapling install。CLI 示例:scrapling extract get 'https://example.com' output.md;scrapling extract fetch 'https://example.com' output.md --css-selector '.dynamic-content' --disable-resources --network-idle;scrapling extract stealthy-fetch 'https://protected-site.com' output.html --solve-cloudflare --block-webrtc --hide-canvas;scrapling extract post 'https://example.com/api' output.json --json '{"query": "search term"}'。Python 中可分别使用 Fetcher、DynamicFetcher、StealthyFetcher 及对应 Session,Spider 支持并发、下载延迟、暂停/恢复(crawldir 检查点)与多会话路由。

限制:需 Python 3.10+;pip 安装后必须运行 scrapling install,否则 DynamicFetcher 与 StealthyFetcher 会失败;DynamicFetcher/StealthyFetcher 超时单位为毫秒(默认 30000),Fetcher 为秒;solve_cloudflare=True 会增加 5-15 秒抓取时间,仅在需要时启用;StealthyFetcher 运行真实浏览器,需限制并发;抓取前应检查 robots.txt 与网站 ToS。