Login To Google Using Perl
In this case I was particularly interested in logging in, so that I could programmatically download my Financial Portfolios, to see information the way I’d like it. I though about building my own database, but why? Google does a fantastic job of doing this for me, and as long as I can grab it with Perl (The greatest language on Earth). Then what is the point of me managing my own MySQL tables, worring about its uptime etc.
So feel free to alter the code, but this will get you into Google. You will most likely just need to alter the url lines and put in your username and password info.
Here is the code:
#!c:\\perl\\bin
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
###go to login page and login.
my $url = “https://www.google.com/accounts/ServiceLogin?hl=en&service=finance&nui=1&continue=http%3A%2F%2Ffinance.google.com%2Ffinance”;
my $username = “yourname@gmail.com”;
my $password = “yourpassword”;
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_number(1);
$mech->field(Email => $username);
$mech->field(Passwd => $password);
$mech->click();
#Go to the next link, now that we are logged in.
$url = ‘http://finance.google.com/finance/portfolio?action=view&pid=1&pview=pview&output=csv’;
$mech->get($url);
my $output_page = $mech->content();
#now you can do something with the content. Remember $output_page is a string ![]()


Jun 6th, 2008 at 2:49 pm
[…] the problem I ran into the other day was I was trying to login to Google Finance using perl, which was also surprisingly easy to do. I wanted just the names in my portfolio so I could use them […]