1

I am using Firefox, iMacros and js.

I have a URLs.txt-file with a list of URLs. In Firefox I have a webpage open in Tab 1. This website contains many URLs. Some of which are in my text file. I am trying to create a simple script that will skip the URLs from my text file and open the other URLs each in the next tabs. 10 at once. So Tab 2-11 should be opened with new URLs that are not in my text file. This is my JavaScript, but it doesn't work:

var macro;
var ret;

macro ="CODE:";
macro +="SET !DATASOURCE URLs.txt"+"\n"
macro +="SET !ERRORIGNORE YES"+"\n";
macro +="TAG POS=1 TYPE=HTML ATTR=* EXTRACT=HTM"+"\n";
macro +="SET !DATASOURCE_LINE {{!LOOP}}"+"\n";

iimPlay(macro)
var text=iimGetExtract();

 if(text.search("00016")!=-1)   {
 ret = iimPlay("donothing.iim");
   }

    else if (ret != -101) {
     ret = iimPlay("openURL.iim");
 }

openURL.iim simply opens tabs with URLs, but in this script it never skips those URLs that are in my list. I need help to fix this code.

this is what openURL.iim looks like (for the first 4 tabs):

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
EVENT TYPE=CLICK SELECTOR="HTML>BODY>UL:nth-of-type(2)>LI>A" BUTTON=0 MODIFIERS="ctrl"
EVENT TYPE=CLICK SELECTOR="HTML>BODY>UL:nth-of-type(2)>LI:nth-of-type(2)>A" BUTTON=0 MODIFIERS="ctrl"
EVENT TYPE=CLICK SELECTOR="HTML>BODY>UL:nth-of-type(2)>LI:nth-of-type(3)>A" BUTTON=0 MODIFIERS="ctrl"
EVENT TYPE=CLICK SELECTOR="HTML>BODY>UL:nth-of-type(2)>LI:nth-of-type(4)>A" BUTTON=0 MODIFIERS="ctrl"
EVENT TYPE=CLICK SELECTOR="HTML>BODY>UL:nth-of-type(2)>LI:nth-of-type(5)>A" BUTTON=0 MODIFIERS="ctrl"
....
4
  • I am online now. Please anyone who can help let me know. Commented Oct 2, 2016 at 5:27
  • your script can look totally different. I am only interested in making this work. Obviously my script is insufficient and partly wrong Commented Oct 2, 2016 at 6:50
  • I will make a nice donation to anyone who gets this done. I really need this Commented Oct 2, 2016 at 13:45
  • I can help you with this script. For more convenient conversations contact me via e-mail (see it on my profile page). Commented Oct 3, 2016 at 6:10

1 Answer 1

0

I can give you a clue. Let's make your txt-file with the list of URLs something like this:

"http://www.example1.com
http://www.example2.com
http://www.example3.com"

Pay attention to the fact that there are only two double quotes: at the beginning and at the end of this list.
So your script may look like:

iimPlayCode (
    "SET !DATASOURCE URLs.txt" + "\n" +
    "SET !EXTRACT {{!COL1}}"
);
var excLinks = iimGetExtract().split(/\s+/);

var incLinks = [];
for (i = 1; i <= window.document.querySelectorAll("HTML>BODY>UL:nth-of-type(2)>LI").length; i++)
    if (excLinks.indexOf(window.document.querySelector("HTML>BODY>UL:nth-of-type(2)>LI:nth-of-type(" + i + ")>A").href) == -1)
        incLinks.push(i);

for (i = 0; i < Math.min(incLinks.length, 10); i++)
    iimPlayCode('EVENT TYPE=CLICK SELECTOR="HTML>BODY>UL:nth-of-type(2)>LI:nth-of-type(' + incLinks[i] + ')>A" BUTTON=0 MODIFIERS="ctrl"');

I leave testing this code on the target web site for you.

Sign up to request clarification or add additional context in comments.

1 Comment

wow! Thank you so much. You did an incredible job! I just sent you an email. I would like to add a few more things to this. Please have a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.