Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Mojo::URL returns incorrect absolute path

by Anonymous Monk
on May 16, 2013 at 17:18 UTC ( #1033872=note: print w/replies, xml ) Need Help??

in reply to Mojo::URL returns incorrect absolute path

um, how about code without all that useragent/DOM stuff?
  • Comment on Re: Mojo::URL returns incorrect absolute path

Replies are listed 'Best First'.
Re^2: Mojo::URL returns incorrect absolute path
by mr_p (Scribe) on May 16, 2013 at 17:45 UTC
    I need to use the dom for the links, don't I?

      I need to use the dom for the links, don't I?

      You say there is a problem with Mojo::URL , that it returns incorrect absolute path , meaning  my $link = Mojo::URL->new($e->{href}); gives you the wrong thing

      So as employ Basic debugging checklist , How do I post a question effectively?, to test your hypothesis :)

      use Data::Dumper, dumper the href, and lets see what it does

      You think Mojo::URL is a proble, fantastic, lets check

        #!/usr/bin/perl -- use strict; use warnings; use Mojo::DOM; use Mojo::URL; my $dom = Mojo::DOM->new( '<div> <base href=""> <a href="/bar/">/bar/</a> <a href="baz/biz">baz/biz</a> <a href="#burp">#burp bug </a> </div>' ); #~ $dom->at('base[href]')->each( ## grr $dom->find('base[href]')->each( sub { my( $base , $count ) = @_; $base = $base->attrs('href'); if(length $base ){ $dom->find('a[href]')->each( sub { my ( $link, $count ) = @_; my $href = $link->attrs('href'); $href = Mojo::URL->new($href)->base( Mojo::URL->new($base) ) +->to_abs; #~ $href and $link->attrs(href => $href ); $href and $link->attrs( href => "$href" ); return; }, ); } }, ); for my $l ( $dom->find('a[href]')->each ) { print $l->attrs('href'), "\n"; } __END__

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033872]
[Corion]: 1nickt: I bought a 2015 XPS 13, which is a very nice and shiney (and somewhat overpriced) machine, but I think it's still better priced than an Apple machine. Now it just has to hold up 10 years like the old one did ;)
[1nickt]: Ah, you got Linus' fave? With Ubuntu? 4k display?
[1nickt]: ( The 17" monster I just bought is for my wife, who doesn;t leave the house with it...)
[Corion]: 1nickt: No, I'm using it with Windows 10, but with the 4k display, yes. It's a very nice build IMO, and relatively sturdy. Also, it got 8 or 9 on the ifixit repair scale, which I consider good
[Corion]: ... especially as I expect to have to replace the battery set in two or three years' time

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-03-27 13:09 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.