【发布时间】:2021-01-12 00:45:57
【问题描述】:
我在 Node.js 模块中使用 Puppeteer。我使用 XPath 选择器检索 HTML 元素,需要提取 text 属性。
目前我使用:
// Get the element
let ele = await element.$x(`//div[@class="g"][${i}]/div/div/h3/a`);
// Get the text property
const title = await(await ele[0].getProperty('text')).jsonValue();
有什么方法可以做到这一点而不至于如此冗长?
【问题讨论】:
-
我完全同意这种获取 text 属性的方式非常丑陋。