【问题标题】:Scrapy server do not run spiderScrapy 服务器不运行蜘蛛
【发布时间】:2012-09-20 13:56:37
【问题描述】:

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

$ scrapy crawl somesite

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

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

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

【问题讨论】:

    标签: python parsing web-crawler scrapy


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 2014-03-06
      相关资源
      最近更新 更多