exclude URLs when running a script

2019-07-27 03:57发布

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"
....

1条回答
疯言疯语
2楼-- · 2019-07-27 04:48

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.

查看更多
登录 后发表回答