-1
#!/usr/bin/perl

use WWW::Mechanize;
use Compress::Zlib;

my $mech = WWW::Mechanize->new();

my $username = ""; #fill in username here
my $keyword = "";  #fill in password here

my $mobile = $ARGV[0];
my $text = $ARGV[1];

$deb = 1;

print length($text)."\n" if($deb);

$text = $text."\n\n\n\n\n" if(length($text) < 135);

$mech->get("http://wwwl.way2sms.com/content/index.html");
unless($mech->success())
{
 exit;
}
$dest = $mech->response->content;

print "Fetching...\n" if($deb);

if($mech->response->header("Content-Encoding") eq "gzip")
{
 $dest = Compress::Zlib::memGunzip($dest);
 $mech->update_html($dest);
}

$dest =~ s/<form name="loginForm"/<form action='..\/auth.cl' name="loginForm"/g;


$mech->update_html($dest);
$mech->form_with_fields(("username","password"));
$mech->field("username",$username);
$mech->field("password",$keyword);

print "Loggin...\n" if($deb);

$mech->submit_form();

$dest= $mech->response->content;

if($mech->response->header("Content-Encoding") eq "gzip")
{
        $dest = Compress::Zlib::memGunzip($dest);
        $mech->update_html($dest);
}

$mech->get("http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0");
$dest= $mech->response->content;
if($mech->response->header("Content-Encoding") eq "gzip")
{
        $dest = Compress::Zlib::memGunzip($dest);
        $mech->update_html($dest);
}

print "Sending ... \n" if($deb);

$mech->form_with_fields(("MobNo","textArea"));
$mech->field("MobNo",$mobile);
$mech->field("textArea",$text);
$mech->submit_form();

if($mech->success())
{
print "Done \n" if($deb);
}
else
{
print "Failed \n" if($deb);
exit;
}

$dest =  $mech->response->content;
if($mech->response->header("Content-Encoding") eq "gzip")
{
        $dest = Compress::Zlib::memGunzip($dest);
  #print $dest if($deb);
}

if($dest =~ m/successfully/sig)
{
  print "Message sent successfully" if($deb);
}

exit;

运行此代码时会停止并显示错误消息:

./sms.pl 第 65 行中没有请求字段的表单
无法在 /usr/share/perl5/vendor_perl/WWW/Mechanize.pm 第 1348 行的未定义值上调用方法“值”。

4

3 回答 3

3

我猜想没有包含“MobNo”和“textArea”字段的表单http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0,其中确实没有,因为该 URL 的页面甚至没有<body>标签。

于 2010-04-23T04:25:09.517 回答
1
$dest =~ s/<form name="loginForm"/<form action='..\/auth.cl' name="loginForm"/g;

在脚本中找到上述行并将其替换为以下内容

$dest =~ s/<form name="loginForm"/<form action='..\/Login1.action' name="loginForm"/ig; 

这是必需的,因为最近 way2sms 已重组其主页,因此auth.cl表单已重命名为Login1.action

于 2011-10-30T20:50:02.873 回答
0

当我遇到这类问题时,我会打印整个 HTML 页面以便查看。您期望的表格可能不存在。我怀疑你没有得到你认为的页面。

第一页做了相当多的 JavaScript 处理来提交表单。由于WWW::Mechanize不会为您处理任何这些位,我猜您的第一个表单提交在某种程度上是不完整或无效的,所以您得到的下一页是某种错误页面。这是动态网站的一个很常见的问题。

您还可以将 Mech 的功能与支持 JavaScript 的浏览器的功能进行比较。使用某种 HTTP 嗅探工具来观察交易。交互式浏览器是否在做 Mech 没有做的额外事情?

于 2010-04-23T20:22:11.510 回答