gpt4 book ai didi

php - Mechanize 发布错误

转载 作者:行者123 更新时间:2023-12-04 16:20:40 26 4
gpt4 key购买 nike

好吧,花了很多时间来处理这个脚本以使其启动并运行,现在我遇到的唯一问题是偶尔的 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->reload() 命令,该命令返回如下错误:“发布错误 http://www.lordsoflords.com/m3/fight.php:booyaka.pl 第 299 行错误请求”。

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

附加到的函数如下:
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";}
}

在编写脚本方面,我不是专家,我将不胜感激有关如何纠正此问题或覆盖 Mechanize 超时的任何见解。

最佳答案

使用 Try::Tiny 捕获异常或其他什么,稍等(用 exponential back-off ),然后重新发送请求。对重试上限进行硬编码是常见的 Internet 礼貌,这样您就不会最终破坏服务器。

关于php - Mechanize 发布错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19660411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com