我是Scrapy的新手,我正在寻找一种从Python脚本运行它的方法.我找到了两个解释这个的来源:
http://tryolabs.com/Blog/2011/09/27/calling-scrapy-python-script/
http://snipplr.com/view/67006/using-scrapy-from-a-script/
我无法弄清楚我应该在哪里放置我的蜘蛛代码以及如何从主函数中调用它.请帮忙.这是示例代码:
# This snippet can be used to run scrapy spiders independent of scrapyd or the scrapy command line tool and use it from a script.
#
# The multiprocessing library is used in order to work around a bug in Twisted, in which you cannot restart an already running reactor or in this case a scrapy instance.
#
# [Here](http://groups.google.com/group/scrapy-users/browse_thread/thread/f332fc5b749d401a) is the mailing-list discussion for this snippet.
#!/usr/bin/python
import os
os.environ.setdefault('SCRAPY_SETTINGS_MODULE', 'project.settings') #Must be at the …Run Code Online (Sandbox Code Playgroud) 我想使用scrapy来抓取网页.有没有办法从终端本身传递起始URL?
在文档中给出了可以给出蜘蛛的名称或URL,但是当我给出url时它会抛出一个错误:
//我的蜘蛛的名字就是例子,但是我给的是url而不是我的蜘蛛名字(如果我给蜘蛛名字,它可以正常工作).
scrapy crawl example.com
错误:
文件"/usr/local/lib/python2.7/dist-packages/Scrapy-0.14.1-py2.7.egg/scrapy/spidermanager.py",第43行,在create raise KeyError("未找到蜘蛛:% s"%spider_name"KeyError:'找不到蜘蛛:example.com'
如何让scrapy在终端上给出的url上使用我的蜘蛛?
嗨我在我的Mac上安装了Python Scrapy,我试图在他们的网站上关注第一个例子.
他们试图运行命令:
scrapy crawl mininova.org -o scraped_data.json -t json
Run Code Online (Sandbox Code Playgroud)
我不太明白这是什么意思?看起来scrapy原来是一个单独的程序.而且我认为他们没有一个名为crawl的命令.在示例中,它们有一段代码,它是MininovaSpider类和TorrentItem的定义.我不知道这两个类应该去哪里,转到同一个文件,这个python文件的名称是什么?