我收到上述错误,因为脚本试图加载" var ul"在加载页面{{!COL1}}之前。如何在页面加载后才能运行它。
var macro;
macro = "CODE:";
macro += "SET !DATASOURCE C:\\imacros\\artmi.csv" + "\n";
macro += "SET !DATASOURCE_COLUMNS 3" + "\n"
macro += "URL GOTO={{!COL1}}" + "\n";
var ul = window.content.document.getElementsByClassName("vd-doc")[0].getElementsByTagName("li");
for (var i = 0; i < ul.length; ++i) {
macro += "TAG POS={{i}} TYPE=A ATTR=HREF:*" + "\n";
macro += "TAG POS=1 TYPE=H1 ATTR=* EXTRACT=TXT" + "\n";
macro += "SAVEAS TYPE=EXTRACT FOLDER=C:\\imacros FILE=artmi23.csv" + "\n";
}
iimPlay(macro);
答案 0 :(得分:0)
试试这个
document.addEventListener("DOMContentLoaded", function () {
// Put your code here ...
});
答案 1 :(得分:0)
var macro;
macro = "CODE:";
macro += "SET !DATASOURCE C:\\imacros\\artmi.csv" + "\n";
macro += "SET !DATASOURCE_COLUMNS 3" + "\n"
macro += "URL GOTO={{!COL1}}" + "\n";
for (var i = 0; i < ul.length; ++i) {
macro += "TAG POS={{i}} TYPE=A ATTR=HREF:*" + "\n";
macro += "TAG POS=1 TYPE=H1 ATTR=* EXTRACT=TXT" + "\n";
macro += "SAVEAS TYPE=EXTRACT FOLDER=C:\\imacros FILE=artmi23.csv" + "\n";
iimPlay(macro);
var ul = window.content.document.getElementsByClassName("vd-doc")[0].getElementsByTagName("li");
}
这段代码更有意义。