关于 scrape-ensure-project
scrape-ensure-project 用于创建或检查配置了 web-poet 页面对象和 Zyte API 的 Scrapy 项目。它可从模板创建项目,或检查现有项目的依赖项。
主要功能
- 01从模板创建项目
- 02配置 scrapy-poet 和 Zyte API
- 03检查现有项目的依赖项
- 04确保存在 fixtures 目录
适用场景
- 01启动用于页面对象的 Scrapy 项目
- 02检查现有项目的依赖项
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ zytedata/ skills --skill scrape-ensure-project安装后在 Claude Code 中输入/scrape-ensure-project确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/project-template/cookiecutter.jsonassets/project-template/{{cookiecutter.project_name}}/pyproject.tomlscrapy.cfgassets/project-template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/__init__.pyitems.pysettings.pyassets/project-template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/pages/__init__.pyassets/project-template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/spiders/__init__.pyassets/project-template/{{cookiecutter.project_name}}/fixtures/.gitkeep详细介绍
确保 Scrapy 项目存在,并已正确配置 web-poet 页面对象和 Zyte API。
阅读 ${CLAUDE_SKILL_DIR}/../scrape/references/python-environments.md。
输入
原始参数字符串为 $ARGUMENTS。将其拆分为 2 个以空格分隔的位置参数:
- project_dir:项目目录(例如
./books-project) - project_name:Python 包名称(例如
books_project)
流程
1. 检查项目是否已存在
如果 {project_dir}/pyproject.toml 存在,则这是一个现有项目。转到第 3 步。
否则,从头创建项目(第 2 步)。
2. 创建新项目
使用捆绑的 cookiecutter 模板:
uvx cookiecutter --no-input ${CLAUDE_SKILL_DIR}/assets/project-template -o PARENT_DIR project_name=PROJECT_NAME
这将创建一个 Scrapy 项目,其中包含:
pyproject.toml,含有依赖项(scrapy、scrapy-poet、scrapy-zyte-api、web-poet)scrapy.cfg,含有部署设置settings.py,已配置 scrapy-poet 和 Zyte API 插件pages/、spiders/、fixtures/目录items.py(空文件,可用于编写条目类)
然后安装:
cd PROJECT_DIR && uv sync
报告创建的内容并返回。
3. 验证现有项目的依赖项
读取项目的 pyproject.toml,并检查 dependencies 中是否包含以下包:
scrapyscrapy-poetweb-poetextructprice-parserpytest
如果缺少任何依赖项,请警告用户——列出缺少的依赖项并询问是否添加。未经确认,不要修改项目。
还要检查 fixtures/ 目录是否存在(如果不存在则创建——它只是一个目录)。
4. 报告结果
对于新项目:
Created project at {project_dir}:
- {project_name}/settings.py — scrapy-poet + Zyte API configured
- {project_name}/items.py — ready for item classes
- {project_name}/pages/ — ready for page objects
- fixtures/ — ready for test fixtures
对于现有项目:
Using existing project at {project_dir}.
或者,如果缺少依赖项:
Using existing project at {project_dir}.
Warning: missing dependencies: {list}
Add them to pyproject.toml?
评论
支持 Markdown