0

我设置了从命令行完美运行的蜘蛛

$ scrapy crawl somesite

我用这个字符串制作了一个 shell 脚本,并通过 cronjob 运行它。但这是一个非常糟糕的主意,因为爬虫不会等到结束之前的爬虫爬虫。所以我得到了一些非常复杂的结果。所以我试图让爬虫通过

$ scrapy server
$ curl http://localhost:6800/schedule.json -d project=myproject -d spider=spider2

并且没有结果。爬虫不运行。我不知道如何安排蜘蛛运行(例如每 10 分钟一次)。

4

1 回答 1

1

您使用的是哪个版本的 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)
于 2012-09-21T12:24:45.067 回答