2013-10-29 142 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