2013-10-29 144 views
0

好吧,经过许多漫长的时间涌过这个脚本来启动它并运行,现在我遇到的唯一问题是偶尔发生GET和POST错误,导致它重新启动脚本,这非常烦人。机械化发布错误

sub Fight { 
my($cpm); 
$parsed = 0; while ($parsed == 0) {sleep(3); 
$mech->get("http://www.lordsoflords.com/m3/fight_control.php"); 
$a = $mech->content();if ($a =~ m/Skeleton/) {$parsed = 1;}} 
$mech->form_number(2); 
$mech->field("Difficulty", $level); 
$mech->click(); 
$cpm = $mech->content(); 
$cpm =~ m/(\<option\>208.*Duke)/; 
$cpm = $1; 
$cpm =~ s/ - Shadowlord Duke//g; 
$cpm =~ s/\>209/\>/; 
$cpm =~ s/<.*?>//g; 
if($debug == 1) { 
    print $cpm . "\n"; 
} 
$mech->form_number(1); 
$mech->select("Monster", $cpm); 
$mech->click(); 
$a = $mech->content(); 
$a =~ m/(You win.*exp)/; 
$a =~ m/(battle)/; 
$a =~ m/(You have been jailed for violating our rules)/; 
print $1 . "\n"; 
my $antal = 500 + int rand (500); 
my $antal = 5000; 
my $jail; 

# REPEAT: 
while($antal > 0) { 
    sleep($loopwait); #default = 0.3 
    $antal = $antal -1; 
    $mech->reload(); 
    $a = $mech->content(); 
    $b = $a; 
    $c = $a; 

一号线我得到的错误是在其中返回,看起来像这样的错误重复部分的$ mech->重装()命令:“发布信息时出错http://www.lordsoflords.com/m3/fight.php:在booyaka错误的请求。 pl line 299“。

有时还返回此错误“错误获取http://www.lordsoflords.com/m3/steal.php:无法连接到www.lordsoflords.com:80(错误的主机名)在booyaka.pl 97行”。

此连接到的功能如下:

sub Stealwait { 
    $stealwait = 3600; 
    $stealtime = time; 
    $stealtime = $stealtime + $stealwait; # if stealer can't be found, click for 1k seconds 
    print time . "|" . $stealtime . "\n"; 
    print "stealtime: " . $stealtime . "\n"; 
    $parsed = 0; $stealcount = 0; 
    while ($parsed == 0) {sleep(3); 
    print $stealcount . "\n"; 
    $mech->get("http://www.lordsoflords.com/m3/steal.php"); 
    $a = $mech->content(); 
    if ($a =~ m/Parsed/) {$parsed = 1; $stealwait = 0;} 
    $stealcount = $stealcount+1; if ($stealcount == 5) { 
    } 
if ($a =~ m/recover/) 
{ 
    $a = $mech->content(); 
    $a =~ m/(Take.*This)/s; 
    $b = $1; 
    $b =~ s/<.*?>//sg; 
    $b =~ m/(Take.*seconds)/s; 
    $b = $1; 
    print $b . "\n"; 
    $b =~ m/(for.*seconds)/s; 
    $b = $1; 
    $b =~ s/for//sg; 
    $b =~ s/seconds//sg; 
    $b =~ s/<.*?>//sg; 
    $b =~ s/,//g; 
      $b = 2*$b; 
      $stealwait = $b; 
      print "In recover, gotta wait " . $stealwait . " seconds before I can steal...\n"; 
      $stealtime = time; 
      $stealtime = $stealtime + $stealwait; 
    } 


    sub Steal { 
$parsed = 0; while ($parsed == 0) {sleep(3); 
$mech->get("http://www.lordsoflords.com/m3/steal.php"); 
$a = $mech->content();if ($a =~ m/Parsed/) {$parsed = 1;}} 
    $a = $mech->content(); 
    if ($a =~ m/Freeplay/) { # steal only if we have freeplay 
      $a = "\<option\>" . "$stealchar" . ".*?\<\/option\>"; 
      $tmp = $mech->content(); 
      #print $tmp; 
      if($tmp =~ m/($a)/) {print "Stealer found\n";} else {print "Stealer not found! - not stealing!\n"; return();} 
      $tmp =~ m/($a)/s; 
      $tmp = $1; 
      $tmp =~ s/<.*?>//sg; 
      print "Stealing from: " . $tmp; 
      $mech->form_name(0); 
      $mech->select("Opp", $tmp); 
      $mech->click_button('value' => 'Steal Stats or Items'); 
      $a = $mech->content(); 
      $a =~ m/(sleepers.*This)/s; 
      $b = $1; 
      $b =~ s/<.*?>//sg; 
      $b =~ s/sleepers//sg; 
      $b =~ s/This//sg; 
      print $b; 
    } else {$stealtime = time; $stealtime = $stealtime + 2000; print "Freeplay not detected, stealing cancelled...\n";} 
} 

我不是专家,当涉及到脚本,并在我会如何解决这个问题或覆盖机械化任何见解超时将不胜感激。

+0

从实际指出你的Perl代码中的299和97行开始。 – TLP

+2

加''严格;使用警告;',修复大量错误和警告,如果问题依然存在,那么您将毫无疑问地重新发布您的问题。大多数错误无疑是关于使用显式包名的,这是通过在它们使用的块中用'my $ foo'声明变量来解决的。另外,不要使用'$ a'和'$ b',因为它们被保留用于'sort'函数。 – TLP

+0

299是#REPEAT节中的第一个块,即mech-> reload()行,就像我在原始文章中写的一样。 99是第一个$ mech-> get(“http://www.lordsoflords.com/m3/steal.php”);从第二个代码块 – user2926415

回答

1

Try::Tiny或其他什么来捕捉异常,等一下(用exponential back-off),然后重新发送请求。硬编码重试的上限是常见的互联网礼貌,所以你最终不会敲打服务器。

+0

我之前去过网站,而且我记得阅读关于“退出的原因”是每秒执行一次请求的速度更快。 – TLP

+0

是的,你是正确的,但是这个脚本以前在请求上限内建的服务器内运行良好。有一个loopwait变量设置为shell脚本,用于调整重新加载的等待时间 – user2926415

+0

与我无法找到最初随脚本一起提供的PXPerl版本有关的事实是否可以处理?我自己编译了包管理器中的很多库和模块列表,但是有可能我错过了某些东西来处理这种可能存在的东西?我们正在谈论像一个8岁的PXPerl版本,这是最初编写的。 – user2926415