Ever since I asked how to parse html with regex and got bashed a bit (rightfully so), I've been studying HTML::TreeBuilder, HTML::Parser, HTML::TokeParser, and HTML::Elements Perl modules.
I have HTML like this:
<div id="listSubtitlesFilm">
<dt id="a1">
<a href="/45/subtitles-67624.aspx">
.45 (2006)
</a>
</dt>
</div>
I want to parse out the /45/subtitles-67624.asp
, but more importantly I want to know how to parse out the contents of the div.
I was given this example on a previous question:
while ( my $anchor = $parser->get_tag('a') ) {
if ( my $href = $anchor->get_attr('href') ) {
#http://subscene.com/english/Sit-Down-Shut-Up-First-Season/subtitles-272112.aspx
push @dnldLinks, $1 if $href =~ m!/subtitle-(\d{2,8})\.aspx!;
}
This worked perfectly for that, but when I tried to edit it a bit and use it on a `div
it didn't work. Here is the code I tried:
I tried using this code:
while (my $anchor = $p->get_tag("dt")) {
if($stuff = $anchor->get_attr('a1')) {
print $stuff."\n";
}
}