Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: In a Web Page forms are displayed as empty

by Preceptor (Deacon)
on Mar 30, 2007 at 10:52 UTC ( [id://607437]=note: print w/replies, xml ) Need Help??


in reply to In a Web Page forms are displayed as empty

Well, if you're not getting any errors, then ... yes, you should have some content.

If you're looking at just checking it works, is there a reason you're not using $mech -> content to see what you're actually fetching? I'd consider it more likely that something's up with your forms processing, than something trivial like a web page fetch...

Replies are listed 'Best First'.
Re^2: In a Web Page forms are displayed as empty
by jesuashok (Curate) on May 04, 2007 at 06:30 UTC
    Hi Preceptor,

    Sorry for the delayed comment.
    As you suggested I used $mech -> content. I got the following output.

    #!/usr/bin/perl use WWW::Mechanize ; use LWP::Debug qw(+); use strict; use warnings; use Data::Dumper; my $mech = WWW::Mechanize->new ; $mech->proxy(['http','ftp'], 'http://63.117.9.150:8080/'); #Fetch URL or Die Tryin' $mech ->get("http://<application_ip>:8082/metrica_root/Login") ; if ( $mech ->success ) { print "Connection Success ", $mech ->res->sta +tus_line, "\n"; } else { print "Status :" , $mech ->res->status_line , + "\n"; } my @webforms = $mech->forms(); print Dumper [ @webforms ]; print "Trying to print the content ......\n"; $mech->content; foreach my $form (@webforms) { my @inputfields = $form->param; foreach my $inputfield (@inputfields) { print Dumper [ $inputfield ]; } print Dumper [ $form ]; }
    Output :- LWP::UserAgent::new: () LWP::UserAgent::proxy: ARRAY(0x1bf0e28) http://63.117.9.150:8080/ LWP::UserAgent::proxy: http http://63.117.9.150:8080/ LWP::UserAgent::proxy: ftp http://63.117.9.150:8080/ LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking 155.226.230.173 for cookies HTTP::Cookies::add_cookie_header: Checking .226.230.173 for cookies HTTP::Cookies::add_cookie_header: Checking 226.230.173 for cookies HTTP::Cookies::add_cookie_header: Checking .230.173 for cookies HTTP::Cookies::add_cookie_header: Checking 230.173 for cookies HTTP::Cookies::add_cookie_header: Checking .173 for cookies LWP::UserAgent::send_request: GET http://155.226.230.173:8082/metrica_ +root/Login LWP::UserAgent::_need_proxy: Proxied to http://63.117.9.150:8080/ LWP::Protocol::http::request: () LWP::Protocol::collect: read 266 bytes LWP::Protocol::collect: read 301 bytes HTTP::Cookies::extract_cookies: Set cookie JSESSIONID => 0000000000000 +01a49444c3 a687474702f52657150726f636573736f723a312e30000000000000010000000000000 +0ac0001020 0000000103135352e3232362e3233302e31373300c39300000000004900504d4300000 +0000000001 a49444c3a687474702f52657150726f636573736f723a312e300020200000000974635 +f696e73743 1002020200000000d2f746f6d636174345f706f6100000000000000035649530300000 +0050005070 17f0000000000000000000008000000005649530000000001000000140000000000010 +0010000000 00001010900000000_2925080BF3F637D984812BF731798941 LWP::UserAgent::request: Simple response: OK Connection Success 200 OK $VAR1 = []; Trying to print the content ......
    I don't have any clues to move further on this. I am expecting your valid inputs on the same.
      Hi jesuashok,

      I had a hunch that the pages in question are generated by JavaScript using 'document.write', so I /msg'd you to confirm this. I have seen some pages that use document.write to output html. Let us take for a basic example the following html page:
      <html> <head> <title>Bad Example</title> </head> <body> <script> document.write('<H1>JavaScript made me do it!</H1>') </script> </body> </html>
      Now the following Perl code:
      #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get('http://yourserverhere/test.html'); print $mech->content( format => "text" );
      Which outputs: "Bad Example". Why? Because "Please note that Mech does NOT support JavaScript. Please check the FAQ in WWW::Mechanize::FAQ for more.".

      You can use Win32::IE::Mechanize or Mozilla::Mechanize or alike to control a browser which does know how to deal with JavaScript. This is another reason to always refer to the documentation.

      Update: Excuse the lack of error checking in the Perl script above, I wanted to get this post to you ASAP and I have to attend a project meeting.

      Hope this helps

      Martin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found