A sample HTML table is displayed below:
<tr class="row-class" role="row">
<td>Text1</td>
<td>
<form method='get' action='http://example.php'>
<input type='hidden' name='id_num' value='ABCD123'> <!-- < I NEED THIS VALUE -->
<button type='submit' class='btn' title='Check' ></button>
</form>
</td>
</tr>
The goal is to extract the value of the hidden input named id_num
. (For this illustration, the expected value is "ABCD123").
An attempt was made to parse the code using cheerio as showcased here:
var $ = cheerio.load(body);
$('tr').each(function(i, tr){
var children = $(this).children();
var x = children.eq(0);
var id_num = children.eq(1);
var row = {
"x": x.text().trim(), //this is correct, value is Text1
"id_num": id_num.text().trim() //Results in an empty string (""). The desired output should be "ABCD123"
};
});
However, only the first value is correctly retrieved.
Is there a way to obtain the value from the hidden input element id_num
?
Appreciate any assistance provided.