运行脚本时排除URL [英] exclude URLs when running a script
问题描述
我正在使用Firefox,iMacros和js.
I am using Firefox, iMacros and js.
我有一个 URLs.txt 文件,其中包含URL列表.在Firefox中,我在选项卡1中打开了网页.该网站包含许多URL.其中一些在我的文本文件中. 我正在尝试创建一个简单的脚本,该脚本将跳过文本文件中的URL,并在下一个选项卡中分别打开其他URL.一次10个.因此,应该使用我的文本文件中没有的新URL打开选项卡2-11. 这是我的JavaScript,但不起作用:
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只是打开带有URL的选项卡,但是在此脚本中,它永远不会跳过列表中的URL.我需要帮助来修复此代码.
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.
这是openURL.iim的样子(对于前4个标签):
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"
....
推荐答案
我可以给您一个提示.让我们使用如下URL列表来创建txt文件:
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.
这篇关于运行脚本时排除URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!