【问题标题】:list spiders from scrapy shell and run individual spider从 scrapy shell 中列出蜘蛛并运行单个蜘蛛
【发布时间】:2016-02-25 03:42:47
【问题描述】:

我想从终端的“scrapy 项目文件夹”中访问scrapy shell。并想列出我项目中所有可用的蜘蛛。我也喜欢运行单个蜘蛛并玩弄响应。

一旦我进入scrapy shell,我会得到以下对象:

[s] Available Scrapy objects:
[s]   crawler    <scrapy.crawler.Crawler object at 0x10b75cbd0>
[s]   item       {}
[s]   settings   <scrapy.settings.Settings object at 0x10cba1b90>
[s] Useful shortcuts:
[s]   shelp()           Shell help (print this help)
[s]   fetch(req_or_url) Fetch request (or URL) and update local objects
[s]   view(response)    View response in a browser

我最好的猜测是,我使用“爬虫”对象中的方法来列出可用的蜘蛛。但我没有运气。另外,一旦我列出它,请让我知道如何运行蜘蛛。

【问题讨论】:

    标签: web-scraping scrapy scrapy-spider scrapy-shell


    【解决方案1】:

    列出我项目中所有可用的蜘蛛

    使用crawler.spiders.list():

    >>> for spider_name in crawler.spiders.list():
    ...     print(spider_name)
    

    【讨论】:

    • 它显示了蜘蛛列表,但你现在如何从外壳本身运行单个蜘蛛?例如:如果我想从第一个蜘蛛那里获得响应并玩响应,然后再稍后如果我想爬取不同的蜘蛛以获得它的响应,我该怎么做?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    • 2017-02-15
    • 1970-01-01
    相关资源
    最近更新 更多