[英]How to retrieve inner text of a xpath?
I want the inner text from a xpath我想要来自 xpath 的内部文本
I'm trying this, but so far I cannot get the text我正在尝试这个,但到目前为止我无法获得文本
const download = await frame.$x(xpath);
const downloadText = await download[0].getProperty('textContent');
console.log(downloadText);
That throws as a result, the following结果抛出以下内容
JSHandle {
...
_targetType: 'page',
_sessionId: '14CCB014112B47319CA8A1C810F23B18'
},
_remoteObject: { type: 'string', value: '20200129_1500.zip' },
_disposed: false
}
I want to retrieve the value that's in _remoteObject, I've tried almost everything I've found and nothing seems to work for me.我想检索 _remoteObject 中的值,我已经尝试了几乎所有我发现的东西,但似乎没有什么对我有用。
Help me please.请帮帮我。
这工作得很好!
const text = await (await download[0].getProperty('textContent')).jsonValue();
You need to use jsonValue()
:您需要使用
jsonValue()
:
const download = await frame.$x(xpath);
const downloadText = await download[0].getProperty('textContent');
console.log(await downloadText.jsonValue());
Alternatively, you can just pass the element to evaluate
:或者,您可以只传递元素来
evaluate
:
const downloadText = await page.evaluate(el => el.textContent, download[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.