Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

get AdSense income?


hi all
I want to use perl script to login my Google Account and get the AdSense
today income. My code is below. But it seems not work correctly. Can someone
help me?

use WWW::Mechanize;
use Crypt::SSleay;

my $mech=WWW::Mechanize->new();
$mech->get("http://www.google.com/intl/en/");
$mech->success or die $mech->response->status_line;

$mech->follow_link(text=>'Sign in');
$mech->success or die $mech->response->status_line;
$mech->field('continue'=>'http://www.google.com/intl/en/');
$mech->field('hl'=>'en');
$mech->field('Email'=>'xxxxxxxx');
$mech->field('Passwd'=>'xxxxxxxx');
$mech->field('PersistentCookie'=>'yes');
$mech->field('rmShown'=>'1');
$mech->field('signIn'=>'Sign in');
$mech->submit();
$mech->success or die $mech->response->status_line;

$mech->follow_link(text=>'My Account');
$mech->success or die $mech->response->status_line;

$mech->follow_link(text=>'AdSense');
$mech->success or die $mech->response->status_line;

.................

On May 24, 9:16 am, "jck11" <j@msr.pchome.com.tw> wrote:

> My code is below. But it seems not work correctly.

Please define "not work correctly."  Do you get Perl errors?  Do you
get errors from $mech->response?

It's hard to help you fix a problem when we don't know what the
problem is.

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

On May 24, 12:16 pm, "jck11" <j@msr.pchome.com.tw> wrote:

> I want to use perl script to login my Google Account and get the AdSense
> today income. My code is below. But it seems not work correctly.

That is a phenomenally unhelpful error description.  How does it not
work?  What results do you see?  How do those results contradict the
desired results?  Are you getting syntax errors?  Runtime errors?
What are the error messages?  Incorrect output?  No output?  Crash?
Freeze?  Infinite loop?

Put more care into your post, and you're more likely to get a helpful
response.

Paul Lalli

Sorry for my mindless question. I should have described it clearly.
I run the code in dos command "perl mycode.pl > a.txt".
When the script run over, I open the a.txt and see the content below.
It seems don't get the right page.
I don't get any error message from  the $mech->response->status_line.

a.txt
=========================================================================== =
==================
    <html> <head> <title>  ????  </title> <meta content="0;
url='http://www.google.com.tw/accounts/SetSID?sidt=1ptDwRIBAAA%3D.fv91FaTps2
kb2XCAwolrFx9g8S6%2BGdBdd1YAckC%2F%2BN1Sqmk9h88KgBja3%2BjsmkizLFKHaTxxpOZ7E i
wWtM3hYi7l23pf3OyBoPtDvVuT014GYmSli56%2FOWzPUyhK7UIX%2FbOhu7EgjnXIuLC%2F1Sk H
YMLCB1MyNpCrXz3McVTDmy6dFXWnvodsWsVLVphqPNTPPnj1AtNrz1nbJbVVjwz3vympDryZmbu h
ckFR%2FzaVczAhSPrfKCo3SgwLJMzwBlPizWKWRFN8i2TtzxHB6%2FAPtg%3D%3D.h2BQhB2fcL 4
5HHNvdI%2Fn4Q%3D%3D&amp;continue=http%3A%2F%2Fwww.google.com.tw%2F'"
http-equiv="refresh">   </head> <body alink="#ff0000" text="#000000"
vlink="#551a8b" link="#0000cc" bgcolor="#ffffff"> <script
type="text/javascript" language="javascript"><!--

location.replace("http://www.google.com.tw/accounts/SetSID?sidt\u003d1ptDwRI
BAAA%3D.fv91FaTps2kb2XCAwolrFx9g8S6%2BGdBdd1YAckC%2F%2BN1Sqmk9h88KgBja3%2Bj s
mkizLFKHaTxxpOZ7EiwWtM3hYi7l23pf3OyBoPtDvVuT014GYmSli56%2FOWzPUyhK7UIX%2FbO h
u7EgjnXIuLC%2F1SkHYMLCB1MyNpCrXz3McVTDmy6dFXWnvodsWsVLVphqPNTPPnj1AtNrz1nbJ b
VVjwz3vympDryZmbuhckFR%2FzaVczAhSPrfKCo3SgwLJMzwBlPizWKWRFN8i2TtzxHB6%2FAPt g
%3D%3D.h2BQhB2fcL45HHNvdI%2Fn4Q%3D%3D&continue\u003dhttp%3A%2F%2Fwww.google.
com.tw%2F")
  //--> </script> </body> </html>
=========================================================================== =
==================

my code
=========================================================================== =
==================
use WWW::Mechanize;
use Crypt::SSleay;

my $mech=WWW::Mechanize->new();
$mech->get("http://www.google.com.tw/");
$mech->success or die $mech->response->status_line;

$mech->follow_link(text=>'??');
$mech->success or die $mech->response->status_line;
$mech->field('continue'=>'http://www.google.com.tw/');
$mech->field('hl'=>'zh-TW');
$mech->field('Email'=>xxxxxxxx);
$mech->field('Passwd'=>'xxxxxxxx');
$mech->field('PersistentCookie'=>'yes');
$mech->field('rmShown'=>'1');
$mech->field('signIn'=>'??');
$mech->submit();
$mech->success or die $mech->response->status_line;

$mech->follow_link(text=>'????');
$mech->success or die $mech->response->status_line;

$mech->follow_link(text=>'AdSense');
$mech->success or die $mech->response->status_line;
print $mech->content;
=========================================================================== =
==================

jck11 wrote:
> Sorry for my mindless question. I should have described it clearly.
> I run the code in dos command "perl mycode.pl > a.txt".
> When the script run over, I open the a.txt and see the content below.
> It seems don't get the right page.
> I don't get any error message from  the $mech->response->status_line.

You received HTML, what did you expect?

> a.txt
> =========================================================================== =
> ==================
>     <html> <head> <title>  ????  </title> <meta content="0;
> url='http://www.google.com.tw/...

> location.replace("http://www.google.com.tw/...")
>   //--> </script> </body> </html>

Javascript is redirecting the browser to another URL, that's what the
location.replace does. Spend a little time, on your own, to try to
get your program to do what you want.  You received Javascript,
simply reading some documentation would have told you what
that call would do, within a browser.

As for a fix, possibly parse the new URL, from the above
HTML, and make another get() to the new URL. If the new URL is
always the same, then hard-code it into your script and do one
get().

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc