Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Mojo::URL returns incorrect absolute path

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


in reply to Re^2: Mojo::URL returns incorrect absolute path
in thread Mojo::URL returns incorrect absolute path

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


Comment on Re^3: Mojo::URL returns incorrect absolute path
Download Code
Re^4: Mojo::URL returns incorrect absolute path
by Anonymous Monk on May 17, 2013 at 04:21 UTC
    #!/usr/bin/perl -- use strict; use warnings; use Mojo::DOM; use Mojo::URL; my $dom = Mojo::DOM->new( '<div> <base href="http://example.com/foo/page"> <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__ http://example.com/bar/ http://example.com/foo/baz/biz http://example.com/foo/page#burp

      I am sorry that I did not mention that I ran Data::Dumper on it.

      I did run Data::Dumper on it. It had two parts for 'page' 'page'.

      This problem does not happen all the time. it only happens sometimes.

        :)really? why not share the dumpered data, instead of an external url that can change?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2015-07-03 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls