我有Imacros代码从我的php脚本中提取文本/数据,我的php脚本运行良好,但它通常会出错,因为它是通过API从其他人那里获取数据。
所以我需要检查一下,在我的Imacros运行之前,我的php脚本是否已完全加载。所以我需要在javaScript中使用它,因为使用" if-else语句" (Imacros不支持这个),我在Javascript中非常新,希望有人可以修复我的javascript代码,这里是:
var macro;
macro = "CODE:";
macro +="SET !EXTRACT_TEST_POPUP NO"+"\n";
macro +="SET !DATASOURCE MASTER-ID.txt"+"\n";
macro +="SET !DATASOURCE_COLUMNS 2"+"\n";
macro +="SET !DATASOURCE_LINE {{i}}"+"\n";
macro +="TAB T=1"+"\n";
macro +="URL GOTO=http://localhost/DataGenerator.php?mid={{!COL1}}"+"\n";
macro +="WAIT SECONDS=0.5"+"\n";
macro +="TAG POS=1 TYPE=B ATTR=* EXTRACT=TXT"+"\n";
[lbl] startcheck: //Re-Check Point
for(i=1;i<51;i++){
iimSet("i",i);
var text=null;
var retvalue = iimPlay(macro);
var text = iimGetLastExtract(1);
if(text=="Warning") // if my php Script Fail to load , then . .
{
alert("TEXT FOUND"); //for testing purpose
alert(text); //for testing purpose
self.location.reload()'; // this is where i want to reload my webpage
[lbl] repeat: goto startcheck; // Jump to Re-Check point
}
else{
alert("TEXT NOT FOUND"); //for testing purpose
iimPlay("my-imacros.iim")
}
}
希望有人可以修复我的javascript代码,因为&#34;跳转到重新检查点&#34;并在Javascript中重新加载,最糟糕的是我将使用&#34; iimPlay(&#34; reload.iim&#34;)&#34;重新加载页面
答案 0 :(得分:2)
我自己解决了这个问题。解决方案是:
macro +="WAIT SECONDS=0.5"+"\n";
macro +="TAG POS=1 TYPE=B ATTR=* EXTRACT=TXT"+"\n";
var macrorefresh;
macrorefresh = "CODE:";
macrorefresh +="REFRESH"+"\n";
macrorefresh +="WAIT SECONDS=0.5"+"\n";
for(i=1;i<52;i++){
iimSet("i",i);
var text=null;
var retvalue = iimPlay(macro);
var text = iimGetLastExtract(1);
startcheck:
while(text=="Warning") {
alert(text); //for testing purpose
iimPlay(macrorefresh);
continue startcheck;
}
alert("TEXT NOT FOUND"); //for testing purpose
iimPlay("my-imacros.iim")
}
它的工作原理,谢谢大家试图帮助我的Stackoverflow
答案 1 :(得分:-1)
它是否像这样工作?
示例:
checkpoint:
ret=iimPlay("something.iim");
if(ret<0)
{
break checkpoint;
}