简体   繁体   中英

How to go to new line after each 6 iterations in Imacros

I'm extracting data from a website. In one line in CSV goes six parameters separated by commas, then I need go to new line and so on. When macros increased loop by six I need to go to new line in CSV line.

I tried to do it like this

if(i % 6 === 0) 

but it's not working.

var id = window.document.getElementsByClassName('divtd textcenter vam').length;
var M = "", a=0, b='\\n';
for (var i = 1; i <= id; i++)
    M += 'TAG POS='+i+' TYPE=DIV ATTR=CLASS:"divtd textcenter vam" EXTRACT=TXT\n';
    M += 'SET !EXTRACT EVAL("\'{{!EXTRACT}}\'.replace(/\\\\n/g, \'\');")\n'; 
    M += 'SAVEAS TYPE=EXTRACT FOLDER=* FILE=trafficgoals.csv\n';
    if(i % 6 === 0) {
        iimPlayCode('SET !EXTRACT '+b+'\nSAVEAS TYPE=EXTRACT FOLDER=* FILE=trafficgoals.csv');
    }
    iimPlayCode(M); 

Maybe you need this solution:

var id = window.document.getElementsByClassName('divtd textcenter vam').length;
for (j = 1; j <= Math.ceil(id / 6); j++) {
    var M = "";     
    for (i = 1 + 6 * (j - 1); i <= Math.min(6 * j, id); i++)
        M += 'TAG POS=' + i + ' TYPE=DIV ATTR=CLASS:"divtd textcenter vam" EXTRACT=TXT\n';
    M += 'SET !EXTRACT EVAL("\'{{!EXTRACT}}\'.replace(/\\\\n/g, \'\');")\n'; 
    M += 'SAVEAS TYPE=EXTRACT FOLDER=* FILE=trafficgoals.csv\n';
    iimPlayCode(M); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM