Parsing HTML with HTML::Tree
Hi,
I am trying to parsing the following HTML content:
-- first part
<a href="/GeneralContent/MySearch.aspx?PagePrefix=IN&
"Chicago"
-- second part
"Something here"
I am using HTML:Tree to parse the HTML and what I would like to do is
that whenever there isn't any <a href=.....> segment as in the second
part of the HTML, I will print something else, such as "Error
occurred". Notice that both first and second parts of the HTML have
common text of "<td class="storyTitle">", which I use for search
criteria.
My problem is that I don't know what the following code will return
whenever <a href=...> is not found. I tried to test against "" or
undef, but doesn't seem to work.
The following is some of my code and it doesn't work as I wish.
use strict;
use LWP::Simple;
use HTML::Tree;
if ($td->attr('class') eq 'storyTitle')
{
if (my $sym = $td->find('a'))
{
if ($sym->as_text() ne '')
{
print $sym->as_text() . "\n";
}
else
{
print "Error Occurred" . "\n";
}
}
Quote:
}