from scrapy import log
from scrapy.contrib.spiders import XMLFeedSpider
from myproject.items import TestItem class MySpider(XMLFeedSpider):
name = 'example.com'
allowed_domains = ['example.com']
start_urls = ['http://www.example.com/feed.xml']
iterator = 'iternodes' # This is actually unnecessary, since it's the default value
itertag = 'item' #开始进行迭代的节点名称 def parse_node(self, response, node):
log.msg('Hi, this is a <%s> node!: %s' % (self.itertag, ''.join(node.extract()))) item = TestItem()
item['id'] = node.xpath('@id').extract()
item['name'] = node.xpath('name').extract()
item['description'] = node.xpath('description').extract()
return item
iterator
用于确定使用哪个迭代器的string。可选项有:
默认值为 iternodes
。