【问题标题】:scrapy works on command line,but not sublimescrapy 在命令行上工作,但不是崇高的
【发布时间】:2018-11-30 01:43:47
【问题描述】:

我正在使用 sublime texteditor3,当我构建文件时,实际上什么也没做,当我从命令行运行时它工作正常,我需要在 sublime 上安装软件包才能在那里运行还是我应该怎么做?(我是在 Windows 上使用 python 3.7)

这是来自scrapy网站的代码

import scrapy


class QuotesSpider(scrapy.Spider):
    name = "quotes"

    def start_requests(self):
        urls = [
            'http://quotes.toscrape.com/page/1/',
            'http://quotes.toscrape.com/page/2/',
        ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)

    def parse(self, response):
        page = response.url.split("/")[-2]
        filename = 'quotes-%s.html' % page
        with open(filename, 'wb') as f:
            f.write(response.body)
        self.log('Saved file %s' % filename)

当我在 sublime 中运行时,我没有收到错误,但没有创建文件。

【问题讨论】:

  • 你是如何在 sublime 中运行它的?
  • ctrl-b ,我不确定我是否理解你的问题
  • 看看这个:stackoverflow.com/questions/23161604/…你有没有建立一个文件来解释要使用什么版本的python?
  • @Lewis 3.7.0(v3.7.0:1bf9cc5093,2018 年 6 月 27 日,04:06:47)[MSC v.1914 32 位(英特尔)]

标签: python python-3.x scrapy


【解决方案1】:

你不能直接从 sublime 运行蜘蛛。

您必须创建带有内容的附加 python 文件

from scrapy import cmdline    
cmdline.execute("scrapy crawl spider_name".split())

用scrapy项目目录更改它的工作目录,然后运行它。

【讨论】:

  • 不起作用,得到与之前相同的错误ModuleNotFoundError: No module named 'wikiSpider'
  • 似乎是工作目录问题。更改保存 scrapy.cfg 文件的运行目录,它将运行。
猜你喜欢
  • 1970-01-01
  • 2017-09-24
  • 1970-01-01
  • 2016-09-09
  • 2013-10-23
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
相关资源
最近更新 更多