我有几个iMacro文件,用一个javascript文件执行。
非常基本,看起来像这样。
iimPlay("GoogleMacro.iim");
iimPlay("IBMMacro.iim");
iimPlay("IMDBMacro.iim");
iimPlay("AltavistaMacro.iim");
iimPlay("GametrailersMacro.iim");
iimPlay("MortalCombatMacro.iim");
iimPlay("WikipediaMacro.iim");
它被称为 playme.js ,并且效果非常好。
但是,我不希望每次启动.js文件时都运行每个宏。
我有一个单独的CSV文件 urldata.csv
URLINFO,URLINFO2,DATA1,DATA2
http://google.com,GOOGLE,"hello","thank you for searching"
http://ibm.com,IBM,null,null
http://imdb.com,IMDB,null,null
http://altavista.com,ALTAVISTA,"rip","rest in peace, my friend",
http://gametrailers.com,GAMETRAILERS,null,null
http://mortalkombat.wikia.com,MORTALKOMBAT,null,null
http://wikipedia.org,WIKIPEDIA,null,null
我想要它的工作方式,在这种情况下( urldata.csv 上面的数据),.js文件只会执行GoogleMacro.iim和AltavistaMacro.iim
我正在寻找的规则:如果COL3的值为 null ,请不要使用iimPlay,并检查下一个文件。
.JS代码工作(我非常清楚这只是胡言乱语),就像这样:
#Import urldata.csv
Loop whole CSV {
ROW2, If COL3 = null --> go to ROW3
else iimPlay("GoogleMacro.iim");
ROW3, If COL3 = null --> go to ROW4
else iimPlay("IBMMacro.iim");
Etc..
}
我需要弄明白:
请帮忙! :)
答案 0 :(得分:2)
<强>解决!强>
将.csv更改为以下内容:
"http://google.com",GoogleMacro,"hello","thank you for searching"
"http://ibm.com",IBMMacro,"",""
"http://imdb.com",IMDBMacro,"",""
"http://altavista.com,ALTAVISTAMacro","rip","rest in peace, my friend",
"http://gametrailers.com",GAMETRAILERSMacro,"",""
"http://mortalkombat.wikia.com",MORTALKOMBATMacro,"",""
"http://wikipedia.org",WIKIPEDIAMacro,"",""
得到了一些非常好的帮助.js
var load;
load = "CODE:";
load += "SET !DATASOURCE urldata.csv" + "\n";
load += "SET !DATASOURCE_COLUMNS 4" + "\n";
load += "SET !DATASOURCE_LINE {{i}}" + "\n";
load += "SET !extract {{!col2}}" + "\n";
load += "ADD !extract {{!col3}}" + "\n";
var siteName = "";
var siteContent = "";
//Change 4 to the number of websites
for(i=1;i<4;i++) {
iimSet("i",i);
// Load data
iimPlay(load);
siteName = iimGetLastExtract(1);
// Check if the website has content
siteContent = iimGetLastExtract(2);
if(siteName != "Website" && siteContent != "") {
iimPlay(siteName + '.iim');
} else {
}
}
答案 1 :(得分:0)
发出GET请求以获取CSV文件的内容(jQuery可能有帮助),然后使用CSV解析器(可能是https://stackoverflow.com/a/14991797/711902)来解析文件,然后循环遍历每一行,并调用如果它符合您的期望,则起作用。
jQuery.get('urldata.csv', function(response) {
var data = parseCSV(response);
for (var i = 1; i < data.length; i++) {
var col3 = data[2], url = data[0];
if (col3 != 'null') {
var site = getSiteFromUrl(url);
iimPlay(site + 'Macro.iim');
}
}
});
function getSiteFromUrl(url) {
var site = url.match(/\/\/(.*)\./)[1];
return site[0].toUpperCase() + site.substr(1);
}