Scraping data without having to explicitly define each field to be scraped

后端 未结 4 848
情深已故
情深已故 2021-02-04 15:06

I want to scrape a page of data (using the Python Scrapy library) without having to define each individual field on the page. Instead I want to dynamically generate fields using

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 15:35

    This works with version 0.24 and also allows Items to work with Item Loaders:

    import scrapy
    from collections import defaultdict
    
    class FlexibleItem(scrapy.Item):
        fields = defaultdict(scrapy.Field)
    
        def __setitem__(self, key, value):
            # all keys are supported
            self._values[key] = value
    

提交回复
热议问题