Web scraping 将csv数据放入阵列imacros js

Web scraping 将csv数据放入阵列imacros js,web-scraping,imacros,Web Scraping,Imacros,我试图循环通过一个csv文件,将每一列推入一个数组,但我不确定如何做到这一点,我知道标记{!COL1}将为我提供所需的数据,但我不知道如何将其保存到一个变量中,我可以使用该变量将其推入数组中 csvToArray = "CODE:"; csvToArray += "SET !DATASOURCE artist.csv" + "\n"; csvToArray += "SET !ERRORIGNORE YES" + "\n"; csvToArray += "SET !DATASOURCE_LINE

我试图循环通过一个csv文件,将每一列推入一个数组,但我不确定如何做到这一点,我知道标记{!COL1}将为我提供所需的数据,但我不知道如何将其保存到一个变量中,我可以使用该变量将其推入数组中

csvToArray = "CODE:";
csvToArray += "SET !DATASOURCE artist.csv" + "\n";
csvToArray += "SET !ERRORIGNORE YES" + "\n";
csvToArray += "SET !DATASOURCE_LINE {{CSV}}" + "\n";
csvToArray += "SET !VAR1 {{!COL1}}" + "\n";

for(i = 0; i < 10; i++){
iimSet("CSV", i);
iimPlay(csvToArray);
}

这段代码将允许我循环浏览csv文件,{{!COL1}}标记提供我想要的数据,我如何将其保存到变量中?我可以使用,请有人帮助我解决这个问题:

要获取COL1的数据,需要设置EXTRACT=COL1,然后将变量分配给iimGetLastExtract

将此项添加到宏:

csvToArray += "SET !EXTRACT {{!COL1}}";
然后将其添加到js文件中:

var myArray = []; // place at top of file for readability
myArray.push(iimGetLastExtract()); // place at end of for loop
                                   // puts each extraction into myArray

请尝试下面的代码块

function read_file(path) {
var content = '', i = 1, f, res = '',spl;

 while (1){
    content = res;      
    if (content != "") {
    spl = content.split("|"); 
    //spl[0] will contain the Row1 and Column1 value, spl[1] will contain Row 1 and Column 2 value etc.,
    /*Here you can specify your script/conditions
    Example:
    iimPlay('CODE:TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:login[username] CONTENT='+spl[0]);
    iimPlay('CODE:TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:login[password] CONTENT='+spl[1]);

I used the infinite loop, so in order to come out of the loop, you need to add a condition like below

if (spl[0]=="End") {//In your input sheet if the Row1,Col1 contains the value 'End', then it will exit the loop
        iimDisplay("All Rows Completed");
        return;
    }   

    */ 
    f = "CODE: "+"\n";
    f += "SET !EXTRACT null" + "\n"; 
    f += "SET !LOOP 3" + "\n"; 
    f += "SET !DATASOURCE \""+path+"\" "+"\n";
    f += "SET !DATASOURCE_COLUMNS 5" + "\n"; //Assume that you have five columns in the your input file
    f += "SET !DATASOURCE_LINE " + i + "\n"; 
    f += "SET !EXTRACT {{!col1}}|{{!col2}}|{{!col3}}|{{!col4}}|{{!col5}}" + "\n";
    iimPlay(f);        
    res = iimGetLastExtract();
    i++;
}
return content;
}
var file_conten = read_file("yourinputfilename.csv");