运行Scrapy教程时获取NotImplementedError

时间:2017-05-14 00:33:11

标签: scrapy

我正在关注Sc tutorial

我使用了教程中的代码:

#include <stdio.h>

/* function declaration */
int print_binary_number(int decimalNo,int count,int arr[]);

int main ()
{
    int a;

    printf("\nPlease enter an integer:\n");
    scanf("%d",&a);

    print_binary_number(a,0,0);
    return 0;
}

int print_binary_number(int decimalNo,int count,int arr[])
{
    int binaryNo,remainder,factor = 1,c;

    if (decimalNo == 0) {
        return 0;
        printf("000");
    }

    if(decimalNo != 0){

        remainder = decimalNo % 2;
        arr[count]=remainder;
        binaryNo = (binaryNo + (remainder * factor));
        factor = factor * 10;

        print_binary_number(decimalNo - 1,count,arr);
        c=1+print_binary_number(decimalNo / 2,count++,arr);

    }
    printf("%d",arr[count]);
    return 0;
}

当我运行命令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) 时,我得到以下输出:

scrapy crawl quotes

出了什么问题?

2 个答案:

答案 0 :(得分:0)

不应该行

page = response.url.split("/)[-2]")

page = response.url.split("/)[-1]")

现在看起来您正在选择单词page并想要一个数字?

答案 1 :(得分:0)

此错误表示您未实现parse功能。但根据你的帖子,你做到了。所以它可能是缩进错误。你的代码应该是这样的:

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 = 'filename'
        with open(filename,'w+') as f:
            f.write(response.body)
            self.log('Saved file %s' % filename)

我测试了它并且有效。