首页 > 解决方案 > Scrapy TabError:标识中制表符和空格的使用不一致

问题描述

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.Requests(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)

当我使用“scrapy crawl quotes”执行此文件时,我在第 7 行遇到错误,它标记了我的“[”并说:TabError:在标识中使用制表符和空格不一致,但我想知道为什么,因为我假设我正确地“复制了” “视频中的代码,我测试了几个身份。目前我正在使用 18.04 ubuntu lts 服务器

标签: python-3.xwebscrapyweb-crawler

解决方案


推荐阅读