mcpField
S
scrape-ensure-project

scrape-ensure-project

github.com/zytedata开发11167 次安装2 天前更新
代码仓库

关于 scrape-ensure-project

scrape-ensure-project 用于创建或检查配置了 web-poet 页面对象和 Zyte API 的 Scrapy 项目。它可从模板创建项目,或检查现有项目的依赖项。

主要功能

  1. 01从模板创建项目
  2. 02配置 scrapy-poet 和 Zyte API
  3. 03检查现有项目的依赖项
  4. 04确保存在 fixtures 目录

适用场景

  1. 01启动用于页面对象的 Scrapy 项目
  2. 02检查现有项目的依赖项

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/zytedata/skills --skill scrape-ensure-project

安装后在 Claude Code 中输入/scrape-ensure-project确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/project-template/
cookiecutter.json
assets/project-template/{{cookiecutter.project_name}}/
pyproject.toml
scrapy.cfg
assets/project-template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/
__init__.py
items.py
settings.py
assets/project-template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/pages/
__init__.py
assets/project-template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/spiders/
__init__.py
assets/project-template/{{cookiecutter.project_name}}/fixtures/
.gitkeep

详细介绍

确保 Scrapy 项目存在,并已正确配置 web-poet 页面对象和 Zyte API。

阅读 ${CLAUDE_SKILL_DIR}/../scrape/references/python-environments.md。

输入

原始参数字符串为 $ARGUMENTS。将其拆分为 2 个以空格分隔的位置参数:

  1. project_dir:项目目录(例如 ./books-project)
  2. 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 中是否包含以下包:

  • scrapy
  • scrapy-poet
  • web-poet
  • extruct
  • price-parser
  • pytest

如果缺少任何依赖项,请警告用户——列出缺少的依赖项并询问是否添加。未经确认,不要修改项目。

还要检查 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