Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
Lately, I have been freelancing and a number of my clients are on linux but still not very computer savvy. Having to start up an Xterm and export a DISPLAY would likely be perceived as clunky software and not win me any repeat business. I considered Running Selenium Headless but that posed its own problems for delivering code to a client. What I needed was a way to make WWW::Mechanize work. I reached for the Firebug Addon to Firefox. The first particular project had 2 hurdles. The first was that clicking on "links" caused the page content to change but the visible URL to stay the same. This was resolved by examining what Firefox was GETing behind the scenes. The next hurdle was that selecting a particular item in a select drop down was sending a JSON request behind the scenes. After much gnashing of teeth, I discovered this little gem
sub post_json { my ($mech, $json, $url) = @_; my $req = HTTP::Request->new(POST => $url); $req->content_type('application/json'); $req->content($json); return $mech->request($req); }
The next project I used Firebug on really had me baffled. The site didn't appear to require Javascript at all and yet I was getting completely different results from WWW::Mechanize and with Firefox. I made sure I was using $mech->agent_alias('Windows Mozilla'); but to no avail. Upon further examining the headers sent between the two, I played a hunch and did the following:
for my $key (keys %ff_header) { $mech->delete_header($key); $mech->add_header($key => $ff_header{$key}); }
It magically started working as expected.
I feel like this is probably old news to most of you and that there are shiny new tools I should be learning. What are they? Do you use certain ones for certain tasks but not others? I realize that some sites will be nearly impossible to automate with WWW::Mechanize without a JavaScript engine and I am fine with that. I am just looking to increase the number of projects I can complete with just mech.
Cheers - L~R
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What Tools Do You Use With WWW::Mechanize
by cavac (Prior) on Oct 03, 2011 at 17:12 UTC | |
by Limbic~Region (Chancellor) on Dec 03, 2011 at 20:03 UTC | |
by cavac (Prior) on Dec 07, 2011 at 15:24 UTC | |
by Limbic~Region (Chancellor) on Dec 07, 2011 at 16:49 UTC | |
Re: What Tools Do You Use With WWW::Mechanize
by OfficeLinebacker (Chaplain) on Oct 03, 2011 at 22:43 UTC | |
by OfficeLinebacker (Chaplain) on Oct 04, 2011 at 18:27 UTC | |
by Limbic~Region (Chancellor) on Oct 04, 2011 at 18:43 UTC | |
by OfficeLinebacker (Chaplain) on Oct 05, 2011 at 13:34 UTC |