How do I fork a process and return results to the user?
Hi, Can anyone help me with this? I have two scripts, the first one calls the exec command which then invokes the second script. The second script then creates a fork process. The child process in the fork does a webservice query which may take a few minutes to return results. What I want to do is forward the user to a Searching for results page which polls periodically for results. Eventually it will display the search results. How can I do this? Once the background fork process is running I have no idea how to get forward the user to a new page and display the results on that page. Any help with this would be great as I'm pretty much stumped. Thank you, G :)
First Mech script: entering a form value (another simple thing no doubt)
Hi all, I managed to get the problem with my script not connecting to the page last night, turned out my web host wouldn't allow it. Got that sorted. Filling in the form should be really simple but I'm getting the following error when trying to set the acOriginAirport field, I thought it might be to do with the javascript on the page but I'm entering a value that the form accepts. The form is being found on the page as I can dump out $agent-forms(); Any ideas anyone? Status: 500 Content-type: text/html Software error: Can't call method value on an undefined value at /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1407. This is my script: #!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use WWW::Mechanize; use HTML::TokeParser; use Data::Dumper; print Content-type: text/html\n\n; print setting up mechbr /; my $agent = WWW::Mechanize-new(); $agent-agent_alias('Windows Mozilla'); print mech setup; $agent-get('http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279'); print setting up airports br /; $agent-field(acOriginAirport, Glasgow GLA); Cheers in advance, G :)
RE: First Mech script: entering a form value (another simple thing no doubt)
Hi, Thanks for replying. As far as I understand it will return undef if no form is found. The form is there so it should do something I would've though, I tried adding in that line anyway using 1 to signify the first (and only) form on the page, still get the same error though :( Cheers, G :) Subject: Re: First Mech script: entering a form value (another simple thing no doubt) From: jimsgib...@gmail.com Date: Thu, 14 Mar 2013 09:27:27 -0700 To: beginners@perl.org On Mar 14, 2013, at 8:27 AM, G M wrote: Hi all, I managed to get the problem with my script not connecting to the page last night, turned out my web host wouldn't allow it. Got that sorted. Filling in the form should be really simple but I'm getting the following error when trying to set the acOriginAirport field, I thought it might be to do with the javascript on the page but I'm entering a value that the form accepts. The form is being found on the page as I can dump out $agent-forms(); Any ideas anyone? Status: 500 Content-type: text/html Software error: Can't call method value on an undefined value at /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1407. This is my script: #!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use WWW::Mechanize; use HTML::TokeParser; use Data::Dumper; print Content-type: text/html\n\n; print setting up mechbr /; my $agent = WWW::Mechanize-new(); $agent-agent_alias('Windows Mozilla'); print mech setup; $agent-get('http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279'); print setting up airports br /; $agent-field(acOriginAirport, Glasgow GLA); I have not used WWW::Mechanize, but from reading the documentation, it would seem you must call $agent-form_number($number) with a form number before making any calls to field(). Line 1407 of Mechanize.pm is part of the field method: sub field { my ($self, $name, $value, $number) = @_; $number ||= 1; my $form = $self-current_form(); if ($number 1) { $form-find_input($name, undef, $number)-value($value); } else { if ( ref($value) eq 'ARRAY' ) { $form-param($name, $value); } else { $form-value($name = $value); # line 1407 } } } The current_form() method is returning null because you have not specified (with a call to form_number()) which form you are using. Hence the error message you are seeing. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: First Mech script: entering a form value (another simple thing no doubt)
Hi, Thanks for that, yeah I can see there are no form tags on that page, I'll give your suggestion a go. Thank you very much! G :) Date: Thu, 14 Mar 2013 16:56:37 + From: dav...@preshweb.co.uk To: beginners@perl.org Subject: Re: First Mech script: entering a form value (another simple thing no doubt) On Thu, 14 Mar 2013 16:42:52 + G M iamnotregiste...@hotmail.com wrote: Hi, Thanks for replying. As far as I understand it will return undef if no form is found. The form is there so it should do something I would've though, I tried adding in that line anyway using 1 to signify the first (and only) form on the page, still get the same error though :( There are no forms on the page. DB6 $mech = WWW::Mechanize-new; DB7 $mech-get( 'http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279'); DB8 x $mech-forms; empty array See also: [davidp@supernova:~]$ wget -q -O- http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279 | grep -i 'form' [davidp@supernova:~]$ WWW::Mechanize wants to be able to find a form to actually submit. You may be able to just fake the request yourself - at a quick glance, it looks like it submits to http://www.easyjet.com/EN/Booking.mvc, so take the field names from the source of the URL you gave before, and POST them at that URL, and see what happens. Failing that, you'll have to use the form in your browser while using an addon like Firebug or something, or capturing HTTP traffic off the wire, and see what happens, and make your script do the same. -- David Precious (bigpresh) dav...@preshweb.co.uk http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook www.preshweb.co.uk/cpanwww.preshweb.co.uk/github -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Mechanize: first attempt at scraping (should be something trivial)
Hi all, I'm making an attempt at my first screen scraping script. For some reason the script doesn't continue after the invocation of the get method on the last line: use strict; use WWW::Mechanize; use HTML::TokeParser; use Data::Dumper; print Content-type: text/html\n\n; print setting up mechbr /; my $agent = WWW::Mechanize-new(); $agent-agent_alias('Windows Mozilla'); print mech setup; $agent-get('http://www.easyjet.com/en/'); Can anyone see anything wrong with this? I've tried double quotes and different urls but it doesn't attempt to get the page. Thanks in advance for any advice on this. G :)
RE: Mechanize: first attempt at scraping (should be something trivial)
Hi, Yeah I tried putting a die line in after doing a bit of googling, I've got a print mech ran line where you've got die, doesn't print anything out though :( Cheers, G Date: Wed, 13 Mar 2013 13:04:39 -0700 Subject: Re: Mechanize: first attempt at scraping (should be something trivial) From: dery...@gmail.com To: iamnotregiste...@hotmail.com CC: beginners@perl.org On Wed, Mar 13, 2013 at 12:09 PM, G M iamnotregiste...@hotmail.com wrote: Hi all, I'm making an attempt at my first screen scraping script. For some reason the script doesn't continue after the invocation of the get method on the last line: use strict; use WWW::Mechanize; use HTML::TokeParser; use Data::Dumper; print Content-type: text/html\n\n; print setting up mechbr /; my $agent = WWW::Mechanize-new(); $agent-agent_alias('Windows Mozilla'); print mech setup; $agent-get('http://www.easyjet.com/en/'); Can anyone see anything wrong with this? I've tried double quotes and different urls but it doesn't attempt to get the page. Hm, what code follows the get? Always a good idea to check for errors in case of site outage for instance. However this worked for me a few moments ago when I tried: $agent-get(...); die $agent-status unless $agent-success; ; print content: $a-content; -- Charles DeRykus
RE: Mechanize: first attempt at scraping (should be something trivial)
Definitely appears to be network related as I'm getting this when using warnings/fatalsToBrowser: Error GETing http://www.easyjet.com/en/: Can't connect to www.easyjet.com:80 (connect: Connection refused) Date: Wed, 13 Mar 2013 14:19:00 -0700 Subject: Re: Mechanize: first attempt at scraping (should be something trivial) From: dery...@gmail.com To: iamnotregiste...@hotmail.com CC: beginners@perl.org On Wed, Mar 13, 2013 at 1:08 PM, G M iamnotregiste...@hotmail.com wrote: Hi, Yeah I tried putting a die line in after doing a bit of googling, I've got a print mech ran line where you've got die, doesn't print anything out though :( Hm, the problem is that Mech by default throws fatal errors so if it couldn't fetch content, your program dies before mech ran occurs. Only if you said $agent-new(autocheck=0), would you see it. You can see the differing output in these: $agent-new(autocheck=0); # toggle 0/1 $agent-get(http://nowhere.com/nono;); print mech ran; -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Forking question
Hi, I'm working on a forking process and I need a way to check if any of the processes have failed and if they have restart them. Can anyone point me in the right direction to a tutorial or explanation of how to do this? Thanks in advance, Graeme