【发布时间】:2016-07-12 17:29:39
【问题描述】:
我正在尝试通过提取所有带有“huis”(荷兰语中的“house”)的链接来抓取网站。关注http://doc.scrapy.org/en/latest/topics/spiders.html,我正在尝试
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from Funda.items import FundaItem
class FundaSpider(scrapy.Spider):
name = "Funda"
allowed_domains = ["funda.nl"]
start_urls = [
"http://www.funda.nl/koop/amsterdam/"
]
rules = (
Rule(LinkExtractor(allow=r'.*huis.*', callback='parse_item'))
)
def parse_item(self, response):
item = FundaItem()
item['title'] = response.extract()
return item
但是,我收到了错误消息
Rule(LinkExtractor(allow=r'.*huis.*', callback='parse_item'))
TypeError: __init__() got an unexpected keyword argument 'callback'
从之前的帖子 (Scrapy Error: TypeError: __init__() got an unexpected keyword argument 'deny') 看来,可能的原因是括号不匹配,因此关键字被传递给 Rule 而不是 LinkExtractor。但是,在我看来,在这种情况下,callback 按预期位于LinkExtractor 括号内。
任何想法是什么导致了这个错误?
【问题讨论】: