python - 试图让 Scrapy 进入项目以运行 Crawl 命令

标签 python scrapy web-crawler

我是 Python 和 Scrapy 的新手,正在学习 Scrapy 教程。我已经能够通过使用 DOS 界面并键入以下内容来创建我的项目:

scrapy startproject dmoz

教程后面提到的Crawl命令:

scrapy crawl dmoz.org

但每次我尝试运行它时,我都会收到一条消息,指出这不是一个合法的命令。进一步环顾四周,看起来我需要进入一个项目,而这正是我无法弄清楚的。我尝试将目录更改为我在 startproject 中创建的“dmoz”文件夹,但它根本无法识别 Scrapy。

我确定我遗漏了一些明显的东西,我希望有人能指出来。

最佳答案

您必须在“startproject”文件夹中执行它。如果它找到您的 scrapy.cfg 文件,您将有另一个命令。你可以在这里看到区别:

$ scrapy startproject bar
$ cd bar/
$ ls
bar  scrapy.cfg
$ scrapy
Scrapy 0.12.0.2536 - project: bar

Usage:
  scrapy <command> [options] [args]

Available commands:
  crawl         Start crawling from a spider or URL
  deploy        Deploy project in Scrapyd target
  fetch         Fetch a URL using the Scrapy downloader
  genspider     Generate new spider using pre-defined templates
  list          List available spiders
  parse         Parse URL (using its spider) and print the results
  queue         Deprecated command. See Scrapyd documentation.
  runserver     Deprecated command. Use 'server' command instead
  runspider     Run a self-contained spider (without creating a project)
  server        Start Scrapyd server for this project
  settings      Get settings values
  shell         Interactive scraping console
  startproject  Create new project
  version       Print Scrapy version
  view          Open URL in browser, as seen by Scrapy

Use "scrapy <command> -h" to see more info about a command


$ cd ..
$ scrapy
Scrapy 0.12.0.2536 - no active project

Usage:
  scrapy <command> [options] [args]

Available commands:
  fetch         Fetch a URL using the Scrapy downloader
  runspider     Run a self-contained spider (without creating a project)
  settings      Get settings values
  shell         Interactive scraping console
  startproject  Create new project
  version       Print Scrapy version
  view          Open URL in browser, as seen by Scrapy

Use "scrapy <command> -h" to see more info about a command

关于python - 试图让 Scrapy 进入项目以运行 Crawl 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4988297/

相关文章:

python - 如何从亚马逊产品页面中提取 asin

java - 使用 URL.openConnection() 时,处理 "www"和 "https"等 URL 变化的最佳方法是什么?

java - 爬虫4j的实现

web-crawler - 抓取整个网络的指南?

python - 检查是否可以使用提供的列表中的单词将字符串拆分为句子

python - 如果投票中有 "tie",带有 ovo 模型的多类 SVC 如何进行预测?

Python/Django - 模板中的If语句围绕扩展

python - 为什么更改 .format 中的变量后,字符串格式的全局变量仍保持不变?

python - 爬行速度在接近尾声时急剧减慢

python - Scrapy 在基本示例上崩溃(无法运行)