Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: retrieving the absolute url

by jeffenstein (Hermit)
on May 21, 2002 at 11:25 UTC ( [id://168084]=note: print w/replies, xml ) Need Help??


in reply to retrieving the absolute url

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:

return if $tag ne 'img'; push(@imgs, $attr{'src'});
or
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:

@imgs = map { $_ = url($_, $base)->abs; } @imgs;
to this:
@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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://168084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-29 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found