admin管理员组文章数量:1208155
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. 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 I'm not able to get the array of these td values.
Can you please help me loop over these values?
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. 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 I'm not able to get the array of these td values.
Can you please help me loop over these values?
Share Improve this question edited Apr 26, 2024 at 21:31 ggorlen 56.9k8 gold badges110 silver badges150 bronze badges asked Sep 9, 2017 at 7:41 Aman GuptaAman Gupta 1,8744 gold badges33 silver badges59 bronze badges1 Answer
Reset to default 22I 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']
本文标签: javascriptHow to get all the child elements values of an html element using puppeteerStack Overflow
版权声明:本文标题:javascript - How to get all the child elements values of an html element using puppeteer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738703972a2107799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论