當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。