我想使用imacros从网站下载相片。我需要根据产品编号更改每张照片的名称。这是我的代码:
var macro;
macro = "CODE:";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "URL GOTO=mywebsite" + "\n";
macro += "TAG POS={{i}} TYPE=IMG ATTR=SRC:Text source" + "\n"; //page where i find the text
macro += "TAG POS=1 TYPE=SPAN FORM=NAME:form1 ATTR=ID:txt2ArtikelNr" + "\n";
macro += "TAG POS=1 TYPE=SPAN ATTR=ID:txt2ArtikelNr EXTRACT=TXT" + "\n"; //This text I intend to use as image name
for (i = 1; i <= 100; i++) {
iimSet("i", i);
iimPlay(macro);
iimGetLastExtract(1);
var inner;
inner = "CODE:";
inner += "SET !ERRORIGNORE YES" + "\n";
inner += "FRAME NAME=Auswahlframe" + "\n";
inner += "TAG POS={{j}} TYPE=IMG ATTR=SRC:image page" + "\n";
inner += "TAG POS=1 TYPE=IMG ATTR=SRC:image sourse" + "\n";
inner += "ONDOWNLOAD FOLDER=* FILE=report_{{!Extract}}_image_{{!NOW:yyyymmdd_hhnnss}}.jpg WAIT=YES" + "\n"; // here I used the extracted text as image name
inner += "TAG POS=1 TYPE=IMG FORM=NAME:form1 ATTR=HREF:Image download address CONTENT=EVENT:SAVEITEM" + "\n";
for (j = 1; j <= 15; j++) {
iimSet("j", j);
iimPlay(inner);
}
}
问题是在iimPlay命令之后,imacro删除存储的(提取的)文本。因此,我保存的图像名称中没有“产品编号”。 有人可以告诉我如何将提取的文本的值从一个循环传递到第二个循环。 THX ...
答案 0 :(得分:1)
您可以使用此代码,因为您可以使用iimSet()方法在imacros代码中设置所需的字符串变量
var macro;
macro = "CODE:";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "URL GOTO=mywebsite" + "\n";
macro += "TAG POS={{i}} TYPE=IMG ATTR=SRC:Text source" + "\n"; //page where i find the text
macro += "TAG POS=1 TYPE=SPAN FORM=NAME:form1 ATTR=ID:txt2ArtikelNr" + "\n";
macro += "TAG POS=1 TYPE=SPAN ATTR=ID:txt2ArtikelNr EXTRACT=TXT" + "\n"; //This text I intend to use as image name
for (i = 1; i <= 100; i++) {
iimSet("i", i);
iimPlay(macro);
var ExtractedTxt = iimGetLastExtract(1);
var inner;
inner = "CODE:";
inner += "SET !ERRORIGNORE YES" + "\n";
inner += "FRAME NAME=Auswahlframe" + "\n";
inner += "TAG POS={{j}} TYPE=IMG ATTR=SRC:image page" + "\n";
inner += "TAG POS=1 TYPE=IMG ATTR=SRC:image sourse" + "\n";
iimSet("ExtractedTxt", ExtractedTxt);
inner += "ONDOWNLOADFOLDER=*FILE=report_{{ExtractedTxt}}_image_{{!NOW:yyyymmdd_hhnnss}}.jpg WAIT=YES" + "\n"; // here I used the extracted text as image name
inner += "TAG POS=1 TYPE=IMG FORM=NAME:form1 ATTR=HREF:Image download address CONTENT=EVENT:SAVEITEM" + "\n";
for (j = 1; j <= 15; j++) {
iimSet("j", j);
iimPlay(inner);
}
}
&#13;
--- -----编辑
您可以使用ECMA6语法使用名为template literal的多行字符串在内部设置变量,如下所示:
macro = `TAG POS=${i} TYPE=IMG ATTR=SRC:Text source`;// i is the variable assigned to macro
&#13;
中使用它