I'm trying to grab the value after the tag and the value is not in the tag in puppetter

Viewed 43

I'm trying to grab this color from this webpage with puppeteer. But I'm having issues to scrape that color correctly.

const productColor_Selector = '.lang1 p:nth-of-type(1)'
const productColor = await page.$eval(productColor_Selector, e => e.textContent)

console.log("color", productColor)

let colorFilter = productColor;
let splitColor = colorFilter.split('Color:');
let colorProduct = splitColor[1].trim().split(' ')[1];

console.log("Final Color:", colorProduct)

As a result of running my code sometimes I get color but it is in a bad format and sometimes it returns as undefined: see the screenshot

1 Answers

You can try something like this:

const colorProduct = await page.evaluate(
  () => document.querySelectorAll('.lang1 p:nth-of-type(1) strong')[1]
          .nextSibling.nodeValue
);
Related