我是 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/