我正在尝试获取标签后的值,而该值不在 puppetter 的标签中

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

我正在尝试用人偶操纵 this color from this webpage。但是我在正确刮掉那个颜色时遇到了问题。

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)

由于 运行 我的代码有时会变色,但格式不正确,有时 returns 为 undefined: see the screenshot

您可以尝试这样的操作:

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