javascript - querySelectorAll() print textcontent of all nodes -
this code using text content webpage. yet not working , not know doing wrong.
<tr style="color:#000000" class="odd"> <td style="padding:5px 5px 5px 10px" align="center"><input type="checkbox" name="cards[]" id="card_278002" value="278002"></td> <td align="center">411756</td> <td align="center">sherrie</td> <td align="center">89852</td> </tr>
and thats js code :
function get42() { return document.queryselectorall('tr>td').textcontent; } console.log(page.evaluate(get42));
output : null
.. doing wrong ?
you can't use document.queryselectorall
that. returns nodelist
. have take textcontent
each node yourself.
longer way:
function get42() { var tds = document.queryselectorall('td'), result = []; (var = 0; < tds.length; i++) { result.push(tds[i].textcontent); } return result; }
or shorter:
function get42() { var tds = document.queryselectorall('td'); return array.prototype.map.call(tds, function(t) { return t.textcontent; }); }
Comments
Post a Comment