Home > database >  How to scrape a particular element (Cheerio)
How to scrape a particular element (Cheerio)

Time:01-26

The website code is <div ><del>16 999</del>15 999</div>

I need to scrape 15 999. How can I do this exactly?

I already tried to do it with selector div.product__price or product__price product__price-promo in which case I get the result "1699915999"

If I try with selector div.product__price > del get the result 16999.

So far I don't know how to get 15 999

CodePudding user response:

You can do:

const b = priceSelectors.map(sel => [...this._$(sel)[0].childNodes].find(n=>n.nodeType==3&&n.data.trim()).data.trim()).find(e=>e) || null;

This goes through the selectors and finds the content of the first non-whitespace text node.

  •  Tags:  
  • Related