Hello Monks,
I've been trying to understand how perl might populate the information of a browser object and then create an actual browser with a GUI thereafter, and I've found that the tool-chain I've been working with is either being misused--by someone of limited experience--or is not up to the task. My endeavor was consistent with the Virtue of Laziness, where one wants to minimize clicks of the same buttons or same text at frequented sites. In particular, I'd like to imitate keystrokes that allow personal banking, where SSL is used, as indicated by 'https' in the url. The documentation of WWW::Mechanize says it can handle SSL, but I get nowhere with it unless I use LWP::UserAgent.
Update
Apparently, the previous sentence is wrong. The following code works exactly how you'd expect, and I believed the latter had failed:
#! /usr/bin/perl use warnings; use strict; use 5.010; use WWW::Mechanize; my $url = 'https://www.huntington.com/'; my $mech = WWW::Mechanize->new; $mech->get($url); my $c = $mech->content; say "c is $c"; my $url2 = 'https://berniesanders.com/issues/racial-justice/'; my $mech2 = WWW::Mechanize->new; $mech2->get($url2); my $c2 = $mech2->content; say "c2 is $c2";
Let's look at some code, one of many tries:
#! /usr/bin/perl use warnings; use strict; use 5.010; use LWP::UserAgent; use HTML::Display; my $url = 'https://www.huntington.com/'; my $ua = LWP::UserAgent->new; $ua->agent( 'Windows Mozilla/5.0'); my $response = $ua->get($url); my $content = $response->content; $ENV{'PERL_HTML_DISPLAY_COMMAND'}='run "C:\Program Files (x86)\Googl +e\Chrome\Application\chrome.exe" %s'; my $browser=HTML::Display->new(); if (defined($browser)) { $browser->display(html=>$content); } else { print("Unable to open browser: $@\n"); }
This succeeds in loading the content from this site, but it is nearly unrecognizable, as the .css does not load, nor anything that depends on relative addressing. What's more, the login link, whilst active, does not function, so it's a complete washout. I've tried variations, but none of them seem to rise above the limitation that this browser believes it's running on my drive and doesn't live on a remote server, as this is a typical url:
file:///C:/cygwin64/tmp/9EQdRdu_5w.htmlMight I have different luck with a different browser? I doubt it following this approach. My question is this: does perl have a browser that it can cook up from scratch, that is with the help of cpan?
Q2) Could I "harvest" the url from an automated session and use it as an argument as a black-box browser were instantiated?
Q3) Has anyone in the history of perl used it to create a means to watch netflix, hbogo or hulu?
Thanks for your comment.
Another Update
My apologies for another revision to the original post. I looked at the responses to another recent node that was somewhat related to mine and found the following resource, which has answered at least two of my questions directly: http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize/Examples.pod
#!/usr/bin/perl # turn on perl's safety features use strict; use warnings; # work out the name of the module we're looking for my $module_name = $ARGV[0] or die "Must specify module name on command line"; # create a new browser use WWW::Mechanize; my $browser = WWW::Mechanize->new(); # tell it to get the main page $browser->get("http://search.cpan.org/"); # okay, fill in the box with the name of the # module we want to look up $browser->form_number(1); $browser->field("query", $module_name); $browser->click(); # click on the link that matches the module name $browser->follow_link( text_regex => $module_name ); my $url = $browser->uri; # launch a browser... system('galeon', $url); exit(0);
Where I'm falling short now is how to rewrite the system command to be appropriate for windows 8. Note that the syntax I used for the HTML::Display program above indeed was able to instantiate chrome.exe, so I feel like I'm close. I wrote a little test program to try to find the right syntax:
#! /usr/bin/perl use warnings; use strict; use 5.010; my $url = 'https://www.youtube.com/watch?v=ju1IMxGSuNE'; system( 'run C:\Program Files (x86)\Google\Chrome\Application\chrome.e +xe', $url ); exit(0);
and got this response from my dos window:
The filename, directory name, or volume label syntax is incorrect.In reply to creating a useful browser from automation by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |