[英]How to get all the child elements values of an html element using puppeteer
I am using puppeteer . 我正在使用木偶戏 。 I want to get the values of column names of a table.
我想获取表的列名的值。
<tbody>
<tr class="GridHeader" align="center" style="background-color:Black;">
<td class="HeaderStyleOfdatalist">XYZ</td>
<td>0500</td>
<td>0550</td>
<td>0600</td>
<td>0650</td>
</tr>
</tbody>
What I need to get is an array of these td values. 我需要得到的是这些td值的数组。 I tried page.$(selector) but could not understand the output.
我试过页面。$(选择器)但无法理解输出。 I also tried:
我也尝试过:
let idAttribute = await page.$eval('.GridHeader', e => e.childNodes);
console.log(idAttribute)
But not able to get the array of these td values. 但是无法获得这些td值的数组。
Can you please help me loop over these values. 你能不能请我帮我循环这些价值观。
EDIT : Found the answer to the problem and posted it in the answers section. 编辑 :找到问题的答案并将其发布在答案部分。
I was able to get the solution using: 我能够使用以下方法获得解决方案:
const data = await page.evaluate(() => {
const tds = Array.from(document.querySelectorAll('.GridHeader td'))
return tds.map(td => td.textContent)
});
console.log(data) // ['xyz', '0500', '0550','0600', '0650']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.