当前位置: 首页>>代码示例>>Python>>正文


Python exporters.XmlItemExporter方法代码示例

本文整理汇总了Python中scrapy.exporters.XmlItemExporter方法的典型用法代码示例。如果您正苦于以下问题:Python exporters.XmlItemExporter方法的具体用法?Python exporters.XmlItemExporter怎么用?Python exporters.XmlItemExporter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scrapy.exporters的用法示例。


在下文中一共展示了exporters.XmlItemExporter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: spider_opened

# 需要导入模块: from scrapy import exporters [as 别名]
# 或者: from scrapy.exporters import XmlItemExporter [as 别名]
def spider_opened(self, spider):
        file_xml = open('%s_items.xml' % spider.name, 'w+b')
        self.files[spider] = file_xml
        self.exporter = XmlItemExporter(file_xml)
        self.exporter.start_exporting() 
开发者ID:zhanghe06,项目名称:scrapy_project,代码行数:7,代码来源:exporter_xml.py

示例2: process_item

# 需要导入模块: from scrapy import exporters [as 别名]
# 或者: from scrapy.exporters import XmlItemExporter [as 别名]
def process_item(self, item, spider):
        """
        Process each item to export them according to their year.
        """
        if not spider.get_body:
            return item

        # Get the year
        time_format = "%Y-%m-%d %H:%M:%S%z"
        timestamp = datetime.strptime(item['timestampReceived'], time_format)
        year = str(timestamp.year)
        filename = self.file_base + year + 'Bodies.xml'

        if year in self.exporters:
            # If we already have an exporter for this year, select it
            exporter = self.exporters[year]['exporter']
        else:
            # If we encounter this year for the first time, then:
            # Open a new file
            dest_file = open(filename, 'wb')

            # Store file and create exporter in dictionary
            self.exporters[year] = {
                'file': dest_file,
                'exporter': XmlItemExporter(dest_file)
            }

            # Initialize the exporter
            exporter = self.exporters[year]['exporter']
            exporter.root_element = 'emails'
            exporter.item_element = 'email'
            exporter.fields_to_export = self.fields_to_export
            exporter.start_exporting()

        # Now we can export the item for real
        exporter.export_item(item)
        return item 
开发者ID:gaalcaras,项目名称:mailingListScraper,代码行数:39,代码来源:pipelines.py

示例3: spider_opened

# 需要导入模块: from scrapy import exporters [as 别名]
# 或者: from scrapy.exporters import XmlItemExporter [as 别名]
def spider_opened(self, spider):
		file = open('pydata_items.xml', 'w+b')
		self.files[spider] = file
		self.exporter = XmlItemExporter(file)
		self.exporter.start_exporting() 
开发者ID:jmortega,项目名称:pydata_webscraping,代码行数:7,代码来源:pipelines.py

示例4: spider_opened

# 需要导入模块: from scrapy import exporters [as 别名]
# 或者: from scrapy.exporters import XmlItemExporter [as 别名]
def spider_opened(self, spider):
		file = open('europython_items.xml', 'w+b')
		self.files[spider] = file
		self.exporter = XmlItemExporter(file)
		self.exporter.start_exporting() 
开发者ID:jmortega,项目名称:pydata_webscraping,代码行数:7,代码来源:pipelines.py


注:本文中的scrapy.exporters.XmlItemExporter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。