【发布时间】:2015-07-31 01:23:25
【问题描述】:
我已经组装了一个蜘蛛,它按预期运行,直到我将关键字 deny 添加到规则中。
这是我的蜘蛛:
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from scrapy.selector import Selector
from bhg.items import BhgItem
class BhgSpider (CrawlSpider):
name = 'bhg'
start_urls = ['http://www.bhg.com/holidays/st-patricks-day/']
rules = (Rule(LinkExtractor(allow=[r'/*'], ),
deny=('blogs/*', 'videos/*', ),
callback='parse_html'), )
def parse_html(self, response):
hxs = Selector(response)
item = BhgItem()
item['title'] = hxs.xpath('//title/text()').extract()
item['h1'] = hxs.xpath('//h1/text()').extract()
item['canonical'] = hxs.xpath('//link[@rel = \"canonical\"]/@href').extract()
item['meta_desc'] = hxs.xpath('//meta[@name=\"description"]/@content').extract()
item['url'] = response.request.url
item['status_code'] = response.status
return item
当我运行这段代码时,我得到:
deny=('blogs/', 'videos/', ),), )
TypeError: __init__() got an unexpected keyword argument 'deny'
我做错了什么?好吧,我猜一个函数或其他东西没有期待额外的参数(deny)但是哪个函数? parse_html()?
我没有定义任何其他蜘蛛,也没有__init__()
【问题讨论】: