simplejsonspider
simplejsonspider 是一个超简单的 Python 工具包,用于请求指定的 JSON API 并将返回内容自动保存为本地 JSON 文件。你只需要指定接口地址、文件名模板和存储路径,即可“一键抓取、自动存储”。注意:该工具包仅支持 JSON 格式的 API 响应。用GPT 4.1 只花了15分钟写的。
特点
- ⚡️ 支持自定义 HTTP headers 和 cookies
- 🗂 文件名模板自由拼接,支持如
{id}_{title}.json - 🧰 用法极简,适合数据抓取、接口快照、API调试等场景
安装
pip install simplejsonspider
快速上手
from simplejsonspider import SimpleJSONSpider
id = 1
title = 'delectus aut autem'
# 创建一个简单的 JSON API 抓取器
spider = SimpleJSONSpider(
api_url='https://jsonplaceholder.typicode.com/todos/1', # API接口
filename_template='{id}_{title}.json', # 文件名模板(对应API返回的字段)
storage_dir='./data' # 存储目录
)
spider.run()
执行后,将自动在 ./data 目录下生成如 1_delectus aut autem.json 的文件,内容即API返回的JSON。
进阶用法:自定义headers与cookies
有些网站需要带自定义User-Agent、Referer或Cookie,直接传递即可:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Referer": "https://www.bilibili.com/"
}
cookies = {
"SESSDATA": "your_cookie"
}
spider = SimpleJSONSpider(
api_url='https://jsonplaceholder.typicode.com/todos/1', # 示例API接口
filename_template='{code}.json', # 根据API返回的字段
storage_dir='./bili_data',
headers=headers,
cookies=cookies
)
spider.run()
文件名模板说明
- 支持 Python 的字符串格式化:
{id}_{title}.json - 注意:模板里的字段必须是API响应JSON顶层的键。
常见问题
-
遇到 412、403 等错误? 请添加正确的 User-Agent、Referer 或 Cookie(详见进阶用法)。
-
保存多个API数据? 可在循环中多次创建 SimpleJSONSpider 实例,或自己扩展批量功能。
License
MIT License
关于作者
[Zeturn] [GitHub主页]
---
Metadata
Release files for simplejsonspider 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simplejsonspider-0.2.2.tar.gz | 4.1 kB | Without provenance | Details for simplejsonspider-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simplejsonspider-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for simplejsonspider-0.2.2-py3-none-any.whl |
Total release size: 8.1 kB
Release files / simplejsonspider-0.2.2.tar.gz
| Download URL | simplejsonspider-0.2.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35838fde33bc3dd6690296bfd682b1e11af72f838d0f1ce5d5552f4f21acc5d4
|
|
BLAKE2b-256 checksum How to use checksums |
054d9594abb9990073e67fe9a48168a88e7ca3eebf0d35797b820108f695604c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.10.0
|
Release files / simplejsonspider-0.2.2-py3-none-any.whl
| Download URL | simplejsonspider-0.2.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e0d1d9482057bead1d3ea0db344986298e846b99813bcd1f1b01526a4a198ad
|
|
BLAKE2b-256 checksum How to use checksums |
df9159b000761683de124811ba25f4cb31008941402376bdf3681a4574909f91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.10.0
|
Security for simplejsonspider 0.2.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.