First, the comments in this block say one thing, but the code says something different
# Set up a callback that collect image links my @imgs = (); my $callback = sub { my($tag, %attr) = @_; return if $tag ne 'a'; # we only look closer at <img ...> push(@imgs, values %attr); };
You probably want to change this to:
orreturn if $tag ne 'img'; push(@imgs, $attr{'src'});
return if $tag ne 'a'; push(@imgs, $attr{'href'});
Otherwise, if there are other attributes in the tag (alt=, border=) then you may end up getting their values instead.
Also, the abs() method to URI::URL returns a URI::URL object, so you'll need to change this line:
to this:@imgs = map { $_ = url($_, $base)->abs; } @imgs;
@imgs = map { $_ = url($_, $base)->abs->as_string; } @imgs;
Which will give you a string, that can be used instead. For some reason this only fails occasionally, so this may be the problem that you are running into.
In reply to Re: retrieving the absolute url
by jeffenstein
in thread retrieving the absolute url
by costas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |