當前位置: 首頁>>代碼示例>>Python>>正文


Python exporters.JsonItemExporter類代碼示例

本文整理匯總了Python中scrapy.exporters.JsonItemExporter的典型用法代碼示例。如果您正苦於以下問題:Python JsonItemExporter類的具體用法?Python JsonItemExporter怎麽用?Python JsonItemExporter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了JsonItemExporter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: BaseFilePipeline

class BaseFilePipeline(object):
    def __init__(self,saved_path):
        self.files = {}
        self.saved_path = saved_path
        self.exporter = None

    @classmethod
    def from_crawler(cls, crawler):
        pipeline = cls(crawler.settings.get('SAVED_PATH'))
        return pipeline


    def open_spider(self, spider):
        tp = self.gettype()['name']
        filename = '%s_%s.json' % (spider.name,tp)
        filename = os.path.join(self.saved_path,filename)

        file_ = open(filename,'w+b')
        self.files[spider] = file_
        self.exporter = JsonItemExporter(file_,ensure_ascii=False,encoding='utf-8')
        self.exporter.start_exporting()

    def gettype():
        pass

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        file_ = self.files.pop(spider)
        file_.close()
開發者ID:taichao,項目名稱:newsspider,代碼行數:29,代碼來源:pipelines.py

示例2: spider_opened

 def spider_opened(self, spider):
     if spider.__class__ == MayorsSpider:
         mayor_file = open("data/mayor_candidates.json", "w+b")
         council_file = open("data/city_counsils.json", "w+b")
         self.files.append(mayor_file)
         self.files.append(council_file)
         self.mayor_exporter = JsonItemExporter(mayor_file)
         self.council_exporter = JsonItemExporter(council_file)
         self.mayor_exporter.start_exporting()
         self.council_exporter.start_exporting()
     elif spider.__class__ == RegionCountiesSpider:
         counties_file = open("data/region_counties.json", "w+b")
         self.counties_exporter = JsonItemExporter(counties_file)
         self.files.append(counties_file)
開發者ID:Maidan-hackaton,項目名稱:local-elections-2015-scraper,代碼行數:14,代碼來源:pipelines.py

示例3: open_spider

 def open_spider(self, spider):
     # Creates 4 files for storage scraped items
     self.category_file = open('spider/scraped/category.json', 'wb')
     self.category_exporter = JsonItemExporter(self.category_file, encoding="utf-8")
     self.category_exporter.start_exporting()
     self.product_file = open('spider/scraped/product.json', 'wb')
     self.product_exporter = JsonItemExporter(self.product_file, encoding="utf-8")
     self.product_exporter.start_exporting()
     self.shop_file = open('spider/scraped/shop.json', 'wb')
     self.shop_exporter = JsonItemExporter(self.shop_file, encoding="utf-8")
     self.shop_exporter.start_exporting()
     self.product_price_file = open('spider/scraped/productprice.json', 'wb')
     self.product_price_exporter = JsonItemExporter(self.product_price_file, encoding="utf-8")
     self.product_price_exporter.start_exporting()
開發者ID:spsp01,項目名稱:spider_ceneo,代碼行數:14,代碼來源:pipelines.py

示例4: __init__

 def __init__(self, spider_name):
   self.file = open("output/{}_recipes.json".format(spider_name), 'wb')
   self.file.write(
       '{"date_scraped": "%s", "recipes": ' % datetime.datetime.now()
   )
   self.exporter = JsonItemExporter(self.file, encoding='utf-8',
                                    ensure_ascii=False)
   self.exporter.start_exporting()
開發者ID:Chouvic,項目名稱:food2vec,代碼行數:8,代碼來源:pipelines.py

示例5: open_spider

    def open_spider(self, spider):
        tp = self.gettype()['name']
        filename = '%s_%s.json' % (spider.name,tp)
        filename = os.path.join(self.saved_path,filename)

        file_ = open(filename,'w+b')
        self.files[spider] = file_
        self.exporter = JsonItemExporter(file_,ensure_ascii=False,encoding='utf-8')
        self.exporter.start_exporting()
開發者ID:taichao,項目名稱:newsspider,代碼行數:9,代碼來源:pipelines.py

示例6: from_crawler

class JsonPipelineExporterMixin:
    @classmethod
    def from_crawler(cls, crawler):
        pipeline = cls()
        crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
        crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
        return pipeline

    def spider_opened(self, spider):
        file = open('%s_items.json' % spider.name, 'w+b')
        self.files[spider] = file
        self.exporter = JsonItemExporter(file)
        self.exporter.start_exporting()

    def spider_closed(self, spider):
        self.exporter.finish_exporting()
        file = self.files.pop(spider)
        file.close()

    def process_item(self, item, spider):
        item = self.pre_process_item(item)
        self.exporter.export_item(item)
        return item

    def pre_process_item(self, item):
        return item
開發者ID:gilbertoalexsantos,項目名稱:uris,代碼行數:26,代碼來源:mixins.py

示例7: JsonPipeline

class JsonPipeline(object):
    def __init__(self):
        self.files = {}

    @classmethod
    def from_crawler(cls, crawler):
        pipeline = cls()
        crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
        crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
        return pipeline

    def spider_opened(self, spider):
        file = open('/home/gaoliang/Desktop/result.json', 'w+b')
        self.files[spider] = file
        self.exporter = JsonItemExporter(file, ensure_ascii=False)  # 添加ensure_ascii=False用於使json保存中文不亂碼
        self.exporter.start_exporting()

    def spider_closed(self, spider):
        self.exporter.finish_exporting()
        file = self.files.pop(spider)
        file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item
開發者ID:AnnaYe,項目名稱:NjuptSpider,代碼行數:25,代碼來源:pipelines.py

示例8: SaveItemToJson

class SaveItemToJson(object):
    def __init__(self):
        self.files = {}

    @classmethod
    def from_crawler(cls, crawler):
        pipeline = cls()
        crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
        crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
        return pipeline

    def spider_opened(self, spider):
        file = open('%s_items.json' % spider.name, 'w+b')
        self.files[spider] = file
        self.exporter = JsonItemExporter(file=file)
        print self.exporter
        self.exporter.start_exporting()

    def spider_closed(self, spider):
        self.exporter.finish_exporting()
        file = self.files.pop(spider)
        file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item
開發者ID:eatskolnikov,項目名稱:DEVCA2016,代碼行數:26,代碼來源:pipelines.py

示例9: JsonPipeline

class JsonPipeline(object):
  """Save Pipeline output to JSON."""
  def __init__(self, spider_name):
    self.file = open("output/{}_recipes.json".format(spider_name), 'wb')
    self.file.write(
        '{"date_scraped": "%s", "recipes": ' % datetime.datetime.now()
    )
    self.exporter = JsonItemExporter(self.file, encoding='utf-8',
                                     ensure_ascii=False)
    self.exporter.start_exporting()

  @classmethod
  def from_crawler(cls, crawler):
    return cls(
        spider_name=crawler.spider.name
    )

  def close_spider(self):
    self.exporter.finish_exporting()
    self.file.write("}")
    self.file.close()

  def process_item(self, item):
    self.exporter.export_item(item)
    return item
開發者ID:Chouvic,項目名稱:food2vec,代碼行數:25,代碼來源:pipelines.py

示例10: JsonExportPipeline

class JsonExportPipeline(object):
    def __init__(self):
        _log.info('JsonExportPipeline.init....')
        self.files = {}

    @classmethod
    def from_crawler(cls, crawler):
        _log.info('JsonExportPipeline.from_crawler....')
        pipeline = cls()
        crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
        crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
        return pipeline

    def spider_opened(self, spider):
        _log.info('JsonExportPipeline.spider_opened....')
        file = open('%s.json' % spider.name, 'w+b')
        self.files[spider] = file
        self.exporter = JsonItemExporter(file)
        self.exporter.start_exporting()

    def spider_closed(self, spider):
        _log.info('JsonExportPipeline.spider_closed....')
        self.exporter.finish_exporting()
        file = self.files.pop(spider)
        file.close()

    def process_item(self, item, spider):
        _log.info('JsonExportPipeline.process_item....')
        self.exporter.export_item(item)
        return item
開發者ID:65kg,項目名稱:core-scrapy,代碼行數:30,代碼來源:pipelines.py

示例11: JsonExportPipeline

class JsonExportPipeline(object):
    """
    app.pipelines.exporter_json.JsonExportPipeline
    """
    def __init__(self):
        self.files = {}
        self.exporter = None

    @classmethod
    def from_crawler(cls, crawler):
        pipeline = cls()
        crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
        crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
        return pipeline

    def spider_opened(self, spider):
        file_json = open('%s_items.json' % spider.name, 'w+b')
        self.files[spider] = file_json
        self.exporter = JsonItemExporter(file_json)
        self.exporter.start_exporting()

    def spider_closed(self, spider):
        self.exporter.finish_exporting()
        file_json = self.files.pop(spider)
        file_json.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item
開發者ID:zhanghe06,項目名稱:scrapy_project,代碼行數:29,代碼來源:exporter_json.py

示例12: JsonExportPipeline

class JsonExportPipeline(object):

    def __init__(self):
        self.files = {}

    @classmethod
    def from_crawler(cls, crawler):
        pipeline = cls()
        crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
        crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
        return pipeline

    def spider_opened(self, spider):
        file = codecs.open('%s_data.json' % spider.name, 'w+b', encoding='utf-8')
        self.files[spider] = file
        self.exporter = JsonItemExporter(file)
        self.exporter.start_exporting()

    def spider_closed(self, spider):
        self.exporter.finish_exporting()
        file = self.files.pop(spider)
        file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item
開發者ID:bgcolors,項目名稱:ztcrawl,代碼行數:26,代碼來源:pipelines.py

示例13: JsonExporterPipeline

class JsonExporterPipeline(object):
    # 調用scrapy提供的json_export 導出json文件
    def __init__(self):
        self.file = open('articleexport.json','wb')
        self.exporter = JsonItemExporter(self.file,encoding="utf-8",ensure_ascii = False)
        self.exporter.start_exporting()
    def close_spider(self,spider):
        self.exporter.finish_exporting()
        self.file.close()
    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item
開發者ID:201585052,項目名稱:-,代碼行數:12,代碼來源:pipelines.py

示例14: process_item

    def process_item(self, item, spider):

        designer_dir_name = skutils.escape_filename(item['name'])
        designer_dir_path = os.path.join(GlobalState.data_dir, designer_dir_name)
        file_path = os.path.join(designer_dir_path, designer_dir_name)

        # write json file
        with open('%s.json' % file_path, 'w+b') as f:
            exporter = JsonItemExporter(f)
            exporter.start_exporting()
            exporter.export_item(item)
            exporter.finish_exporting()

        # write excel file
        excelutils.write_designer_excel(item, file_path, designer_dir_name)

        return item
開發者ID:sunnykaka,項目名稱:skwander,代碼行數:17,代碼來源:pipelines.py

示例15: VisionsJsonPipeline

class VisionsJsonPipeline(object):
    def __init__(self):
        self.exporter = None

    def open_spider(self, spider):
        self.exporter = JsonItemExporter(open('%s.json' %spider.name, 'wb'))
        self.exporter.start_exporting()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item

    def close_spider(self, spider):
        self.exporter.finish_exporting()
開發者ID:anamarce,項目名稱:Visions-crawler,代碼行數:14,代碼來源:pipelines.py


注:本文中的scrapy.exporters.JsonItemExporter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。