Run macro and pass URL querystring parameters

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
MarkU
Posts: 7
Joined: Thu May 20, 2010 4:03 pm

Run macro and pass URL querystring parameters

Post by MarkU » Thu May 20, 2010 4:42 pm

Is it possible to pass parameters directly to an imacro as part of a URL querystring ?
e.g. http://run.imacros.net/?code=VkVSU0...1hY3JvCg%3D%3D&VAR1=value1&VAR2=value2
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: Run macro and pass URL querystring parameters

Post by Daniel, Tech Support » Fri May 21, 2010 4:12 pm

Hello,

You can't pass parameters, but you can generate those URLs on the fly with correct parameters, which is basically same thing:
http://forum.imacros.net/viewtopic.php?t=3604

Best regards,
Daniel, iOpus Support
MarkU
Posts: 7
Joined: Thu May 20, 2010 4:03 pm

Re: Run macro and pass URL querystring parameters

Post by MarkU » Mon May 24, 2010 11:45 am

Thanks Daniel, that's really very neat.

Before I make a start, can I just check that the code for the Base64 Decoder/Encoder in iMacros is still the same as described in t.3604 (it's a long time since 2007 and might have changed). I think the encoding at opinionatedgeeek.com is now different to that in iMacros as it produces slightly different output from the same input :

Opiniatedgeek:
VkVSU0lPTiBCVUlMRD02NjUwNDA2IFJFQ09SREVSPUZYDQpUQUIgVD0xDQpVUkwgR09UTz1odHRwOi8vd3d3LnN0cmF0Zm9yZC11cG9uLWF2b24uY28udWsvDQpUQUcgUE9TPTY5IFRZUEU9RElWIEFUVFI9VFhUOg0KVEFHIFBPUz0xIFRZUEU9QSBBVFRSPVRYVDpTdGF5PFNQPmluPFNQPldhcndpY2tzaGlyZTxTUD5hbmQ8U1A+dGhlPFNQPkNvdHN3b2xkcw==
iMacros:
VkVSU0lPTiBCVUlMRD02NjUwNDA2IFJFQ09SREVSPUZYDQpUQUIgVD0xDQpVUkwgR09UTz1odHRwOi8vd3d3LnN0cmF0Zm9yZC11cG9uLWF2b24uY28udWsvDQpUQUcgUE9TPTY5IFRZUEU9RElWIEFUVFI9VFhUOg0KVEFHIFBPUz0xIFRZUEU9QSBBVFRSPVRYVDpTdGF5PFNQPmluPFNQPldhcndpY2tzaGlyZTxTUD5hbmQ8U1A%2BdGhlPFNQPkNvdHN3b2xkcw%3D%3D

any view ?
MarkU
Posts: 7
Joined: Thu May 20, 2010 4:03 pm

Re: Run macro and pass URL querystring parameters

Post by MarkU » Wed May 26, 2010 8:48 am

Here's the HTML/Javascript code I'm using to Base64 encode a macro (then decode it just to prove it all works):

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>iMacro Base64 Encode/Decode</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script language=javascript type="text/javascript">

/*
 * iMacro file converted to javascript string variable using Imacros Script Code Creator :
 *  http://sourceforge.net/projects/imacros-codegen/
 */

      var macro;
macro =    "CODE:";
macro +=  "VERSION BUILD=6650406 RECORDER=FX" + "\n";
macro +=  "TAB T=1" + "\n";
macro +=  "URL GOTO=http://www.stratford-upon-avon.co.uk/" + "\n";
macro +=  "TAG POS=69 TYPE=DIV ATTR=TXT:" + "\n";
macro +=  "TAG POS=1 TYPE=A ATTR=TXT:Stay<SP>in<SP>Warwickshire<SP>and<SP>the<SP>Cotswolds" + "\n";

/*
 * Base64 encoder/decoder
 * Javascript from :http://pylonshq.com/pasties/f7fd30acfc9970f638f2ab828d8eddb0
 * Aug 2009
*/

var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){
    if (!base64Str) return -1;
    if (base64Count >= base64Str.length) return -1;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != -1){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != -1){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != -1){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}

function readReverseBase64(){
    if (!base64Str) return -1;
    while (true){
        if (base64Count >= base64Str.length) return -1;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    }
}

function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}

function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != -1
        && (inBuffer[1] = readReverseBase64()) != -1){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != -1){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != -1){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}
//<!-- End of JS from :http://pylonshq.com/pasties/f7fd30a638f2ab828d8eddb0 -->
</script>
 </head>

  <body>
      <script type="text/javascript">
//run encoder
      var str;
      str = macro;

      var eresult = encodeBase64(str)
// write variables
                document.write("base64Str: ")
                document.write (base64Str); document.write("<br />");
                document.write("base64Count: ")
                document.write (base64Count); document.write("<br />");
// write output
                document.write("eresult: ");
                document.write (eresult); document.write("<br />");
                document.write("<br />");
       </script>
       <script type="text/javascript">
//run decoder
       var dresult = decodeBase64(eresult)
 //      var dresult = decodeBase64(test)
// write variables
                document.write("base64Str: ")
                document.write (base64Str); document.write("<br />");
                document.write("base64Count: ")
                document.write (base64Count); document.write("<br />");
// write output 
                document.write("dresult: ");
                document.write(dresult); document.write("<br />");
    </script>
  </body>
</html>
khairy
Posts: 1
Joined: Wed May 26, 2010 1:49 pm

Re: Run macro and pass URL querystring parameters

Post by khairy » Wed May 26, 2010 3:40 pm

MarkU wrote:Thanks Daniel, that's really very neat.

Before I make a start, can I just check that the code for the Base64 Decoder/Encoder in iMacros is still the same as described in t.3604 (it's a long time since 2007 and might have changed). I think the encoding at opinionatedgeeek.com is now different to that in iMacros as it produces slightly different output from the same input :

Opiniatedgeek:
VkVSU0lPTiBCVUlMRD02NjUwNDA2IFJFQ09SREVSPUZYDQpUQUIgVD0xDQpVUkwgR09UTz1odHRwOi8vd3d3LnN0cmF0Zm9yZC11cG9uLWF2b24uY28udWsvDQpUQUcgUE9TPTY5IFRZUEU9RElWIEFUVFI9VFhUOg0KVEFHIFBPUz0xIFRZUEU9QSBBVFRSPVRYVDpTdGF5PFNQPmluPFNQPldhcndpY2tzaGlyZTxTUD5hbmQ8U1A+dGhlPFNQPkNvdHN3b2xkcw==
iMacros:
VkVSU0lPTiBCVUlMRD02NjUwNDA2IFJFQ09SREVSPUZYDQpUQUIgVD0xDQpVUkwgR09UTz1odHRwOi8vd3d3LnN0cmF0Zm9yZC11cG9uLWF2b24uY28udWsvDQpUQUcgUE9TPTY5IFRZUEU9RElWIEFUVFI9VFhUOg0KVEFHIFBPUz0xIFRZUEU9QSBBVFRSPVRYVDpTdGF5PFNQPmluPFNQPldhcndpY2tzaGlyZTxTUD5hbmQ8U1A%2BdGhlPFNQPkNvdHN3b2xkcw%3D%3D

any view ?
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: Run macro and pass URL querystring parameters

Post by Daniel, Tech Support » Thu May 27, 2010 10:29 pm

Hi MarkU,

So, have you actually tried it out? Did it work? The only difference in encoding that I saw were a few extra letters at the very end. I guess those very base-64 encrypted spaces and / or carriage returns.

Best regards,
Daniel, iOpus Support
MarkU
Posts: 7
Joined: Thu May 20, 2010 4:03 pm

Re: Run macro and pass URL querystring parameters

Post by MarkU » Fri May 28, 2010 7:26 am

Hi Daniel, yes I've got it working OK - but I used the javascript code published above, rather than that in t.3604. The code above declares the characterset used to do the encoding (I guess this might differ (?), and would produce variations in the encoding) : anyway it produces the same querystring as the iMacros>Edit>Share button and works fine.

Another tip is to use the imacros_code_creator to produce the javascript string to be encoded : downloadable from: http://sourceforge.net/projects/imacros-codegen/
; the output sometimes a bit of tweaking, replacing \ character with \\ for example]

Regards, MarkU
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: Run macro and pass URL querystring parameters

Post by Daniel, Tech Support » Fri Jun 04, 2010 10:52 am

Hi MarkU,

Thanks for the feedback! Yes, Code Creator is great for producing JavaScript!
Actually, may be it would be a good idea to add Base64 encoding to it. I will give this idea over to our developers.

Best regards,
Daniel, iOpus Support
der_hannes
Posts: 25
Joined: Sat Aug 01, 2009 11:18 am

Re: Run macro and pass URL querystring parameters

Post by der_hannes » Thu Jun 17, 2010 6:51 am

Thanks for the suggestion!
Version 0.0.14 now supports encoding both, macros and JavaScript to (base64 encoded) URLs, cf. http://forum.imacros.net/viewtopic.php?f= ... 994#p22310
Daniel, Tech Support
Posts: 1483
Joined: Tue Jan 26, 2010 11:35 am

Re: Run macro and pass URL querystring parameters

Post by Daniel, Tech Support » Fri Jun 18, 2010 2:32 pm

Thanks Der Hannes!! :)
Daniel, iOpus Support
Post Reply