Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iMacro - Setting Variable + SaveAs CSV

I am looking for help with 2 parts of my iMacro Script...

Part1 - Variable

I am clicking on the follwoing line of a page in order to access the page I need to extract from.

1st Link

TAG POS=**8** TYPE=A FORM=NAME:xxyy ATTR=HREF:https://aaa.aaaa.com/en/administration/xxxx.jsp?reqID=h*

2nd Link

TAG POS=**9** TYPE=A FORM=NAME:xxyy ATTR=HREF:https://aaa.aaaa.com/en/administration/xxxx.jsp?reqID=h*

The tag pos is the variable, how can I get this so that when running on loop, the macro will select the next value on the screen (ie choose 8,9,10)? Some screens have 100 plus links to be clicked on.

Part 2 - Save CSV file

I have the saveas line in my file. But how can I make it so that there is only 1 csv file created (even if macro is runn 50 times)? Also, is there a way to format the CSV file from the iMacros so that each new run starts on another row (currently, all data extracts to row 1 across many columns.)

Thank you in advance,

Adam

like image 326
user2037960 Avatar asked May 06 '26 19:05

user2037960


1 Answers

This will do what you asked. It will loop the macro and each time set the new position number in the macro.

1)

    var macro;

    macro ="CODE:";
    macro +="TAG POS={{number}} TYPE=A FORM=NAME:xxyy ATTR=HREF:https://aaa.aaaa.com/en/administration/xxxx.jsp?reqID=h*"+"\n";


for(var i=1;i<100;i++)
{

iimSet("number",i)
iimPlay(macro)

}

For the solution of part two you will need JavaScript scripting. First part is declaring macro and the second part is initiating the macro and the third part is the function which saves the extracted text into a file. Each time you run it will save in the new line.

2)

var macroExtractSomething;

macroExtractSomething ="CODE:";
macroExtractSomething +="TAG POS=1 TYPE=DIV ATTR=CLASS:some_class_of_some_div EXTRACT=TXT"+"\n";



iimPlay(macroExtractSomething)
var extracted_text=iimGetLastExtract();

WriteFile("C:\\some_folder\\some_file.csv",extracted)




  //This function writes string into a file. It will also create file on that location
    function WriteFile(path,string)
    {

    //import FileUtils.jsm
    Components.utils.import("resource://gre/modules/FileUtils.jsm");
    //declare file
    var file = new FileUtils.File(path);

    //declare file path
    file.initWithPath(path);

    //if it exists move on if not create it
    if (!file.exists())
    {
    file.create(file.NORMAL_FILE_TYPE, 0666);
    }

    var charset = 'EUC-JP';
    var fileStream = Components.classes['@mozilla.org/network/file-output-stream;1']
    .createInstance(Components.interfaces.nsIFileOutputStream);
    fileStream.init(file, 18, 0x200, false);
    var converterStream = Components
    .classes['@mozilla.org/intl/converter-output-stream;1']
    .createInstance(Components.interfaces.nsIConverterOutputStream);
    converterStream.init(fileStream, charset, string.length,
    Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);

    //write file to location
    converterStream.writeString("\r\n"+string);
    converterStream.close();
    fileStream.close();


    }
like image 179
macroscripts Avatar answered May 11 '26 16:05

macroscripts