简体   繁体   中英

Pass variables from javascript to iMacros

I want to run an iMacro to save lots of webpages (threads on a forum). I worked this out in VBA, but couldn't make it run the iMacro.

I have now tried javascript. I want to pass some basic parameters (thread number, start page number, number of pages to save, file type) to the iMacro and then have it loop until all the pages are saved. This is what I've come up with so far.

<script type="text/javascript">
<!--
var THRNO = prompt("Enter thread number”);
var PGST = prompt("Enter page start number”);
var PGNO = prompt("Enter number of pages to save”);
var THRNM = prompt("Enter thread name/identifier for files”);
var FLTP = prompt("Enter save file type”);
var CNTR = 1

do {

var URLN = "http://www.mysite.co.uk/my-forum/showthread.php?t=" & THRNO & "&page=" &   CNTR

var FLNM = THRNM & ".html"

iimSet("URLN", URLN)
iimSet("FLTP", FLTP)
iimSet("FLNM", FLNM)

iimPlay("iMacroUniversal.iim")

CNTR = CNTR + 1

} while (CNTR < PGNO);

//-->
</script>

The code for my iMacro is

URL GOTO=URLN
SAVEAS TYPE=FLTP FOLDER=D:\MyFolder FILE=FLNM
WAIT SECONDS=2

When I wrote this as VBA code in Excel, it would take all the parameters and open up the iMacros interface but not run the iMacro itself (no error messages - just nothing happened). Am aware that I am probably mixing and mangling up my coding languages.

var macro;

macro ="CODE:";
macro +="URL GOTO={{URLN}}"+"\n";
macro +="SAVEAS TYPE={{FLTP}} FOLDER=D:\MyFolder FILE={{FLNM}}"+"\n";
macro +="WAIT SECONDS=2"+"\n";


var THRNO = prompt("Enter thread number”);
var PGST = prompt("Enter page start number”);
var PGNO = prompt("Enter number of pages to save”);
var THRNM = prompt("Enter thread name/identifier for files”);
var FLTP = prompt("Enter save file type”);
var CNTR = 1

do {

var URLN = "http://www.mysite.co.uk/my-forum/showthread.php?t=" + THRNO + "&page=" +   CNTR;

var FLNM = THRNM + ".html"

iimSet("URLN", URLN)
iimSet("FLTP", FLTP)
iimSet("FLNM", FLNM)

iimPlay(macro)

CNTR = CNTR + 1;

} while (CNTR < PGNO);

//-->

Put this in .js file and see will it work.

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