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&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().