【问题标题】:Python Scrapy - Run SpiderPython Scrapy - 运行蜘蛛
【发布时间】:2016-09-01 14:41:54
【问题描述】:

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

跟着基础Scrapy教程@http://doc.scrapy.org/en/latest/intro/overview.html

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

import scrapy


class StackOverflowSpider(scrapy.Spider):
name = 'stackoverflow'
start_urls = ['http://stackoverflow.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 stackoverflow_spider.py -o top-stackoverflow-questions.json

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

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

当然,这是一个简单的解决方案,但我没有得到它.. 在此先感谢。

【问题讨论】:

    标签: python-2.7 scrapy scrapy-spider


    【解决方案1】:

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

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

    【讨论】:

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