http://www.perlmonks.org?node_id=447290

spyders has asked for the wisdom of the Perl Monks concerning the following question:

Sort of repost and something that was discussed earlier in the CB..

I have a small www::mech script that I'm trying to get to work on my web site (CGI). It works in command line just fine but as CGI on my web it it continually reloads infinately and oddly enough it appends my URL into the current URL (who knows why.).

It turns http://spydersubmission.com/cgi-bin/lyrics.pl (this is the real link)
Into http://spydersubmission.com/?http://spydersubmission.com/cgi-bin/lyrics.pl

Someone in the CB said it was working fine as CGI for them. So what could the problem be?

The module wasn't there this morning so I had to download, make a lib and upload. So I thought that's what the problem was. The web host just installed downloaded and installed it themselves and it's still doing the same monkey business.

Can anyone explain this mystery? Does it work on your web server?

#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my $url = "http://www.letssingit.com/frame_menu.html"; my $query = "avril"; use WWW::Mechanize; my $mech = WWW::Mechanize->new(agent=>"wonderbot"); $mech->get($url); print header, start_html("lyrics grabber"); $mech->submit_form( form_name => 'search', fields => { s => $query, l => 'song', # or 'artist' or 'albu +m' or 'lyrics'. }, ); my $content = $mech->content; print $content;

Replies are listed 'Best First'.
Re: www::mechanize reloading page
by jbrugger (Parson) on Apr 13, 2005 at 09:55 UTC
    If you'd done a
    use Data::Dumper; die Dumper($content);
    You'd see this:
    <SCRIPT> if(self==top)top.location.replace("/?"+document.location) </SCRIPT>
    Got it? :-)

    So this would work:
    #!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my $url = "http://www.letssingit.com/frame_menu.html"; my $query = "avril"; use WWW::Mechanize; my $mech = WWW::Mechanize->new(agent=>"wonderbot"); $mech->get($url); print header,start_html("lyrics grabber"); $mech->submit_form( form_name => 'search', fields => { s => $query, l => 'song', # or 'artist' or 'album' or 'lyrics'. }, ); my $content = $mech->content; $content =~ s/self==top//; print $content;


    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!!!

      Made that small s/// and the thing works like a charm! You're so smart! lol

      Thanks!