I have the following html code of a part of a webpage.
<h2 id="failed_process">Failed Process</h2>
<table border="1">
<thead>
<tr>
<th>
<b>pid</b>
</th>
<th>
<b>Priority</b>
</th>
</tr>
</thead>
<tbody>
<tr>
<td id="90"><a href="details.jsp?pid=p_201211162334&refresh=0">p_201211162334</a></td>
<td id="priority_90">NORMAL</td>
</tr>
<tr>
<td id="91"><a href="details.jsp?pid=p_201211163423&refresh=0">p_201211163423</a></td>
<td id="priority_91">NORMAL</td>
</tr>
<tr>
<td id="98"><a href="details.jsp?pid=p_201211166543&refresh=0">p_201211166543</a></td>
<td id="priority_98">NORMAL</td>
</tr>
</tbody>
</table>
<hr>
I need to extract the pid column . The output should look like
pid
p_201211162334
p_201211163423
p_201211166543
The table count for "Failed Process" table is 4. But the problem is if I mention the table count as 4 and if there are no failed tasks in the webpage, it'll go to the next table and fetch the pid's of next table resulting in wrong pid's.
I am using the below code to get the result.
#!/usr/bin/perl
use strict;
use warnings;
use lib qw(..);
use HTML::TableExtract;
my $content = get("URL");
my $te = HTML::TableExtract->new(
headers => [qw(pid)], attribs => { id => 'failed_process' },
);
$te->parse($content);
foreach my $col ($te->rows) {
print ("\t", @$col), "\n";
}
But I am getting the following error:
Can't call method "rows" on an undefined value
` element and on the same line. Please ignore that part of my comment. I have reformatted the HTML in your question for better clarity.