#!/usr/bin/perl
require "$ENV{HOME}/perl/setEnv.pl";
use WWW::Mechanize;
use Mail::Sendmail;
use MIME::QuotedPrint;
use MIME::Base64;
use HTML::TokeParser;
use Encode;
my $username = "xxx";
my $password = "yyy";
my $url = "http://mes/Mes2/LoginForm.jsp";
my $mech = WWW::Mechanize->new();
$mech->get($url);
## Browse the HTML source of the ASP page to get these parameters <br>
$mech->forms("login");
$mech->field("UserName", $username);
$mech->field("PassWord", $password);
$mech->click("button");
$mech->get("http://mes/Mes2/pp_prod_lamp_target_today_efficiency.jsp");
#open FILE ,">/tmp/LampTarget.html";
#print FILE $mech->content;
#close FILE;
#my $p = HTML::TokeParser->new("/tmp/LampTarget.html");
#$p->{textify}{"td"} = "alt";
#$p->{textify}{"th"} = "alt";
#$p->{textify}{"tr"} = "alt";
#$p->{textify}{"/td"} = "alt";
#$p->{textify}{"/th"} = "alt";
#$p->{textify}{"/tr"} = "alt";
#my @texts;
#while (my $token = $p->get_tag("table")) {
# my $text = $p->get_text("table");
# $cnt++;
# next unless($cnt >= 6);
# #print "------------------$cnt-------------------------\n";
# #print "$text\n";
# push @texts, "<table>$text</table>";
#}
&mailLampTarget();
sub mailLampTarget {
my %mail = (
From => 'MIS <web@aot.com.tw>',
To => "ty.ruan\@aot.com.tw",
Subject => "燈泡生產管理報表"
);
$mail{smtp} = "$smtp";
#$message = "$texts[0].$texts[1]";
#print "@texts\n";
$message = $mech->content;
$boundary = "====" . time() . "====";
$mail{'content-type'} = "multipart/html; boundary=\"$boundary\"";
$boundary = '--'.$boundary;
$mail{body} = <<END_OF_BODY;
$boundary
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
$message
$boundary
$boundary--
END_OF_BODY
sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";
}
沒有留言:
張貼留言