Skip to main content

Netspy

PyPI Python CI License Docs

一个上手简单、结构清晰的 Python 爬虫框架: 你只写 start_requestsparse,框架负责调度、下载、重试、去重、批量落库。

单机(AirSpider)到分布式(Spider / TaskSpider / BatchSpider)全部可用, 并支持浏览器 TLS 指纹伪装。 变更见 CHANGELOG,后续规划见 Roadmap

安装

pip install netspy            # 核心
pip install "netspy[all]"     # 含渲染 / 各类存储 / Redis / CLI / 指标 / 指纹伪装

也可以按需装单项:render · mongo · mysql · postgres · elasticsearch · kafka · redis · cli · metrics · curl

快速开始

pip install "netspy[cli]"
netspy create -p news_crawler
cd news_crawler && python main.py

或直接写:

import netspy as mw


class NewsSpider(mw.AirSpider):
    def start_requests(self):
        yield mw.Request("https://news.ycombinator.com/", callback=self.parse)

    def parse(self, request, response):
        for a in response.css("span.titleline > a"):
            yield {"title": a.css("::text").get(), "url": a.css("::attr(href)").get()}


NewsSpider().start()

示例

examples/ 里有可以直接跑的完整例子:

python examples/books_toscrape.py   # 两级抓取:列表页翻页 → 详情页

文档

完整文档:https://apersonw.github.io/netspy/ (本地预览:pip install "netspy[docs]" && mkdocs serve

能力一览

运行时 单进程多线程、优先级队列、结束检测、Ctrl-C 优雅排空、崩溃 dump + retry 回放
网络 Request/Response(httpx + parsel)、自动重试、validate/failed_request 钩子、随机 UA、会话复用
礼貌性 robots.txt(含 Crawl-delay)、per-domain 限速 + 单域并发上限、跨节点全局限速(Redis)、429/503 读 Retry-After 整域降速
稳健性 状态码策略(错误页不当数据入库)、指数退避 + 抖动、同域连续失败熔断、运行时长上限、响应体大小上限 + Content-Type 白名单、SIGINT/SIGTERM 优雅停止、任务租约 + 落库后才销账(节点被硬杀,任务能回收、数据不丢)
分布式 Spider:Redis 队列 + 布隆去重 + 断点续爬 + 种子一次性锁 + 多节点心跳结束检测
任务驱动 TaskSpider 从任务源持续消费;BatchSpider 周期批次采集(任务表状态机 + 进度追踪 + 防丢)
数据 Item/UpdateItemPipeline(Console/CSV/MongoDB/MySQL/PostgreSQL/Elasticsearch/Kafka)、请求级 + Item 级去重(布隆/精确)
渲染 Request(render=True) —— Playwright 渲染池、wait_for/render_time/render_script
反爬 TLS / HTTP2 指纹伪装(impersonate 真实浏览器)、Cloudflare / Akamai 挑战页识别
扩展 下载中间件链、代理池 / 账号池(耗尽时不会悄悄降级成直连或匿名)、掉登录自动换号
观测 Prometheus exporter、卡死/失败率告警(飞书 / 钉钉 / 企业微信 / 邮件,发送失败会记录)、debug=True
开发体验 响应缓存(重跑读本地文件,不再反复打目标站)
工具 netspy create/shell/retry/cachecreate -i --table 读表结构反射生成 Item

开发

conda env create -f environment.yml && conda activate netspy
pre-commit install
pytest && ruff check . && mypy

CI(GitHub Actions):ruff + mypy(strict) + pytest(Python 3.10–3.13)+ mkdocs build。

License

MIT

Release files for netspy 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netspy 1.3.1
File Size Uploaded
netspy-1.3.1.tar.gz 378.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for netspy 1.3.1
File Interpreter ABI Platform
netspy-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 581.5 kB

Release files / netspy-1.3.1.tar.gz

Download URL netspy-1.3.1.tar.gz
Size 378.9 kB
Tags Source
SHA-256 checksum
How to use checksums
176f3e5eefaef6c335f94c0c37efc19c356941a4f723c92b756fd71595a97400
BLAKE2b-256 checksum
How to use checksums
89d2d808cbaf1ceeadd1b1e93b4a21d66a4086f54cada2ad653e12ff4465a853
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / netspy-1.3.1-py3-none-any.whl

Download URL netspy-1.3.1-py3-none-any.whl
Size 202.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb51da354d766ed78d9e80c426327d07812816189b48dce5fe53cf4dc08995dd
BLAKE2b-256 checksum
How to use checksums
c08af3422a3f32c24f04a3e7aad86a113987a4a004612a5a231500b7c008eb6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

1.3.2

2 release files

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page