繁体   English   中英

Scrapy TabError:缩进中的制表符和空格不一致使用

[英]Scrapy TabError: inconsistent use of tabs and spaces in indentation

我想使用scrapy来爬行网站,只是在网站内部,而不是外部链接。
这是我尝试过的:

import scrapy
import json
import uuid
import os
from scrapy.linkextractors import LinkExtractor

class ItemSpider(scrapy.Spider):
    name = "items"
    allowed_domains = ['https://www.website.com']
    start_urls = ['https://www.website.com/post']
    rules = (Rule(LxmlLinkExtractor(allow=()), callback='parse_obj', follow=True),)
    def parse_obj(self, response):
        for link in LxmlLinkExtractor(allow=self.allowed_domains).extract_links(response):
        response_obj = {}
        counter = 1
        for item in response.css(".category-lcd"):
            title = item.css("div.td-post-header > header > h1::text").extract()
            title_name = title[0]
            response_obj[counter] = {
                'demo': item.css("div.td-post-content > blockquote:nth-child(10) > p::text").extract(),
                'title_name': title_name,
                'download_link': item.css("div.td-post-content > blockquote:nth-child(12) > p::text").extract()
            }
            counter += 1
        filename =  str(uuid.uuid4()) + ".json"
        with open(os.path.join('C:/scrapy/tutorial/results/',filename), 'w') as fp:
            json.dump(response_obj, fp)

但是刮板不起作用,怎么了?! 它说 :

Scrapy TabError:缩进中的制表符和空格不一致使用

您需要在此部分添加缩进:

    for link in LxmlLinkExtractor(allow=self.allowed_domains).extract_links(response):
        response_obj = {}
        counter = 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM