【问题标题】:Trying to do a looped search for keywords with imacros尝试使用 imacros 对关键字进行循环搜索
【发布时间】:2026-02-22 02:25:01
【问题描述】:

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

我们的目标是如下:

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

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

【问题讨论】:

    标签: loops imacros keyword-search


    【解决方案1】:

    如果您想执行 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://*.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");
    }
    

    【讨论】:

    • 看我的回复下一个答案,在cmets中不能高效的添加代码。