QuoteCan't call method "attr_get_i" on an undefined value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sub extract {
my $resp = @_;
my $tree = HTML::Tree->new();
$tree->parse($resp);
my $href = $tree->look_down(
"_tag" => "a",
"href" => qr//,
sub {
( $_[0]->attr("href") =~ /^ *(http:|https:|ftp:|mailto:)/)
}
)->attr_get_i("href");
return $href;
}
perldoc HTML::Elementlook_down
Code: (dl )1
2@elements = $h->look_down( ...criteria... );
$first_match = $h->look_down( ...criteria... );
This starts at $h and looks thru its element descendants (in pre-order), looking for elements matching the criteria you specify. In list context, returns all elements that match all the given criteria; in scalar context, returns the first such element (or undef, if nothing matched).
QuoteUnd wenn ich in der Perldoc zu look-down() weiterlese, gewinne ich den Eindruck, dass sich Deine Suchkriterien widersprechen; speziell das Kriterium für "href" und die Code-Referenz.