Array.prototype.pushUnique = function(elem){ var unique = true; for (var i = 0; i < this.length; i++) if (this[i] == elem) unique = false; if (unique) this.push(elem); } Array.prototype.copyUnique = function(){ var a = []; for (var i = 0; i < this.length; i++) a.pushUnique(this[i]); return a; } String.prototype.GetFileName = function(){ if (this.slice(0,4) == "http") return this.slice(this.lastIndexOf("/") + 1); return this; } var wsh = WScript.CreateObject("WScript.Shell"); var fso = WScript.CreateObject("Scripting.FileSystemObject"); var tempDir = fso.GetSpecialFolder(2); var tempName = "downloadedpage.tmp.tmp"; var tempFullName = tempDir + "\\" + tempName; var targetDir = "c:\\2gis"; var url = "http://info.2gis.ru/tambov/products/download"; var regexMask = new RegExp("http://download.2gis.com/arhives/2GISData_Tambov-[^'\"]+.orig.zip", "g"); // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/d5fk67ky%28v%3dvs.84%29 wsh.Run("wget --output-document=\"" + tempFullName + "\" \"" + url + "\"", 1, true); // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/314cz14s%28v%3dvs.84%29 var file = fso.OpenTextFile(tempFullName, 1); var text = file.ReadAll(); file.Close(); fso.DeleteFile(tempFullName); var matches = text.match(regexMask); if (matches == null) { msg("Nothing..."); WScript.Quit(); } var links = matches.copyUnique() for (var i = 0; i < links.length; i++) { if (!fso.FileExists(targetDir + "\\" + links[i].GetFileName())) wsh.Run("wget -P \"" + targetDir + "\" \"" + links[i] + "\"", 1, true); } function msg(s) {WScript.Echo(s);} |