scrapy item loader return list not single value

前端 未结 1 1880
礼貌的吻别
礼貌的吻别 2021-02-18 17:41

I am using scrapy 0.20.

I want to use item loader

this is my code:

l = XPathItemLoader(item=MyItemClass(), response=response)
        l.add_valu         


        
相关标签:
1条回答
  • 2021-02-18 18:27

    You need to set an Input or Output processor. TakeFirst would work perfectly in your case.

    There are multiple places where you can define it, e.g. in the Item definition:

    from scrapy.item import Item, Field
    from scrapy.loader.processors import TakeFirst
    
    class MyItem(Item):
        url = Field(output_processor=TakeFirst())
        title = Field(output_processor=TakeFirst())
        developer = Field(output_processor=TakeFirst())
    

    Or, set a default_output_processor on a XpathItemLoader() instance:

    l.default_output_processor = TakeFirst()
    
    0 讨论(0)
提交回复
热议问题