Skip to content Skip to sidebar Skip to footer

Scrapy Css Selector Ignore Tags And Get Text Only

I have the following HTML :
  • SKU: 483151
  • I was able to select them using : SKU_SELECTOR = '.aaa .bbb .last ::text'

    Solution 1:

    Your css selector has unnecessary space before ::text.

    SKU_SELECTOR = '.aaa .bbb .last ::text'
                                   ^
    

    Space indicates that any decendant-or-self node qualifies for this selector where you want to select only text under self.

    I got it working:

    >[0]: s = Selector(tex='...')
    >[1]: s.css('.last::text').extract()
    <[1]: [u'\n    ', u' 483151\n']
    

    Post a Comment for "Scrapy Css Selector Ignore Tags And Get Text Only"