0

我有一个 csv 文件,其中包含 128 个不同的关键字(1 列,128 行),我试图在当前页面上搜索,如果它找到其中一个以继续执行非常简单的任务,否则提示我说没有找到了关键字。

目标是具有以下内容:

SET !DATASOURCE ...                            'already have this part working
SET !DATASOURCE_COLUMNS 1
SET !DATASOURCE_LINE {{!LOOP}}
{{!LOOP}} = 1
if TAG POS=1 TYPE=* ATTR=TXT:{{!COL1}} = true   'not actual code from here down 
move to next step
elseif {{!LOOP}} +1 = 129
PROMPT "No keyword was found"
END                                             'killing the script
else 
loop++                                          'loop and search for next keyword

如果重要的话,关键字实际上是最后一个块缺少 IE 的 IP 地址。“192.168.0。” 不确定它是否会影响格式化。我相信有更好的方法来做搜索。如果存在关键字,我只是在寻找 0 或 1(是或否响应),然后如果找到,则继续关注链接。

4

1 回答 1

0

如果您想执行条件语句,例如 if-then,您将需要使用脚本语言[1]。我在下面提供了一个遵循您的伪代码的 Javascript 示例。

var datasource, macro, retcode, numberOfLinesInDatasource, aTagWasFound;

datasource = "somedatasource";
numberOfLinesInDatasource = 128;
aTagWasFound = false;

macro = "CODE:";
// change link to a different website
macro += "URL GOTO=http://stackoverflow.com/questions/25467549/trying-to-do-a-looped-search-for-keywords-with-imacros\n";
retcode = iimPlay(macro);

// loop through all lines in datasource
for (var i = 0; i < numberOfLinesInDatasource; i++)
{
  // get the datasource value at this line
    macro = "CODE:";
    macro += "SET DATASOURCE " + datasource + "\n";
    macro += "SET DATASOURCE_COLUMNS 1\n";
    macro += "SET DATASOURCE_LINE " + i + "\n";
    macro += "ADD !EXTRACT {{!COL1}}\n";
    retcode = iimPlay(macro);
    keyword = iimGetLastExtract();

    // search for this keyword
    macro = "CODE:";
    macro += "TAG POS=1 TYPE=* ATTR=TXT:" + keyword + "\n";
    retcode = iimPlay(macro);

    // if retcode is 1 then the tag was found move on to next step
    if (retcode === 1){
        // move on to next step
        aTagWasFound = true;
        break;
    }
    // tag not found try the next value
}

if (!aTagWasFound)
{
    alert("No keyword found");
} else 
{
    alert("Tag Found");
}
于 2014-08-27T00:25:03.237 回答