提取HTM时,它不会将数据保存到文件中

时间:2017-02-22 18:41:12

标签: imacros

我的代码有问题,它只从变量id中提取数据而不提取标题。但是,如果我删除id的提取,标题正在保存,我想这可能是我的HTM提取问题。 有人可以解释我做错了吗?

var i = 1;

while(iimPlayCode('SET !TIMEOUT_STEP 1\nTAG POS='+i+' TYPE=A ATTR=CLASS:"pl-video-title-link*" CONTENT=EVENT:MOUSEOVER')>0) {

    iimPlayCode('TAG POS='+i+' TYPE=A ATTR=CLASS:"pl-video-title-link*" EXTRACT=TXT\n')
    var title = iimGetLastExtract();
    var title = title.replace(/\s+/g, '');
    iimSet('title',title);


    iimPlayCode('TAG POS='+i+' TYPE=TR ATTR=data-video-id:"*" EXTRACT=HTM\n')
    var id = iimGetLastExtract();
    var id = id.match(/data-video-id="(.+?)"/)[1];
    iimSet('id',id);

    iimPlayCode('SET !EXTRACT {{title}}\nSET !EXTRACT {{id}}\nSAVEAS TYPE=EXTRACT FOLDER=* FILE=Output_for_Youtube_Playlist.csv\n');
    i++;
}

1 个答案:

答案 0 :(得分:1)

好吧,我想通了,我忘了在正则表达式的单引号之间放置空格我觉得这是问题而且我重新编写了脚本结构

while(iimPlayCode('SET !TIMEOUT_STEP 1\nTAG POS='+i+' TYPE=A ATTR=CLASS:"pl-video-title-link*" CONTENT=EVENT:MOUSEOVER')>0) {

    iimPlay('Code:'
        + 'TAG POS='+i+' TYPE=A ATTR=CLASS:"pl-video-title-link*" EXTRACT=TXT\n'
        + 'TAG POS='+i+' TYPE=TR ATTR=data-video-id:"*" EXTRACT=HTM\n'
    )

    var title = iimGetExtract(1);
    title = title.replace(/\s+/g, ' ');

    var id = iimGetExtract(2);
    var id = id.match(/data-video-id="(.+?)"/)[1];

    saveRes = 'CODE:';
    saveRes += 'ADD !EXTRACT "'+title+'"' + '\n';
    saveRes += 'ADD !EXTRACT "'+id+'"' + '\n';
    saveRes += 'SAVEAS TYPE=EXTRACT FOLDER=* FILE=Output_for_Youtube_Playlist.csv\n';
    iimPlay(saveRes);
    i++;
}