Python Scrapy - 运行 蜘蛛

Python Scrapy - Run Spider

运行 Python27 在 Windows 机器上...正在尝试使用 Scrapy

遵循基本的 Scrapy 教程@http://doc.scrapy.org/en/latest/intro/overview.html

我创建了以下蜘蛛并将其保存为 Test2 @C:\Python27\Scrapy

import scrapy


class WhosebugSpider(scrapy.Spider):
name = 'Whosebug'
start_urls = ['http://whosebug.com/questions?sort=votes']

def parse(self, response):
    for href in response.css('.question-summary h3 a::attr(href)'):
        full_url = response.urljoin(href.extract())
        yield scrapy.Request(full_url, callback=self.parse_question)

def parse_question(self, response):
    yield {
        'title': response.css('h1 a::text').extract_first(),
        'votes': response.css('.question .vote-count-post::text').extract_first(),
        'body': response.css('.question .post-text').extract_first(),
        'tags': response.css('.question .post-tag::text').extract(),
        'link': response.url,
    }

下一步告诉我 运行 蜘蛛使用 scrapy runspider Whosebug_spider.py -o top-Whosebug-questions.json

但我不知道 运行 那行代码放在哪里。

我习惯于在我的 python 文件末尾 运行 打印或存储到 csv 命令以检索结果。

当然,这是一个简单的解决方法,但我不明白。提前致谢。

您需要在您使用的任何命令行实用程序中执行 运行spider 命令,例如Cygwin、cmd 等

该命令将在您 运行 命令所在的目录中创建一个名为 top-Whosebug-questions.json 的文件。