NameError:未定义名称“ Rule”,但我确实导入了规则库

时间:2018-11-07 16:05:48

标签: python scrapy web-crawler scrapy-spider

我正在用抓地力制作履带,我不能使用Rule(规则)一词,但是我确实将其导入。

stack_crawler.py

ng serve

...

当我执行 因此,我在外壳程序“ NameError:未定义名称'Rule'”中收到此错误消息

有人可以帮助我吗?

import scrapy
from scrapy.contrib.linkextractors import LinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import Selector
from scrapy.item import Item

from stack.items import StackItem


class StackCrawlerSpider(CrawlSpider):
    name = 'stack_crawler'
    allowed_domains = ['stackoverflow.com']
    start_urls = ['http://www.stackoverflow.com/']

    rules = (Rule(LinkExtractor(allow=r'Items/'), callback='parse_item', follow=True),
    )

0 个答案:

没有答案