我设置了爬虫,它完美地从命令行运行,如下所示
$ scrapy crawl somesite
我用这个字符串创建了一个shell脚本,并通过cronjob运行它。但这是一个非常糟糕的想法,因为爬虫不会等待之前的抓取程序结束。所以我得到了一些非常棒的结果。所以我试着运行crawler
$ scrapy server
$ curl http://localhost:6800/schedule.json -d project=myproject -d spider=spider2
并且没有任何结果。Crawler未运行。我不知道如何安排一个爬虫跑(例如每10分钟)。
发布于 2012-09-21 20:24:45
您使用的是哪个版本的Scrapy?
要解决等待结束之前的爬虫程序的问题,请尝试一些简单的控件,如下所示:
#!/usr/bin/python
import os
import traceback
spiderName='someSpider'
# Block file
pid = str(os.getpid())
pidfile = "/tmp/" + spiderName + ".pid"
if os.path.isfile(pidfile):
print "%s is blocked, another process running..." % spiderName
sys.exit()
else:
file(pidfile, 'w').write(pid)
try:
os.chdir('/some/dir/crawlers')
os.execl('/usr/local/bin/scrapy', 'foo', 'crawl', spiderName)
except OSError:
print str(traceback.format_exc())
os.unlink(pidfile)
https://stackoverflow.com/questions/12514216
复制相似问题