本帖最后由 flashercs 于 2018-10-6 10:07 编辑
- function showError(e,t){tsLog.WriteLine("[object Error]"===Object.prototype.toString.call(e)?[e.name,"source: "+(void 0===t?"":t),"number: "+(e.number>>>0).toString(16),"equipment: "+(e.number>>16&8191),"code: "+(65535&e.number),"Information: "+e.message].join("\r\n"):e)}function getHTML(e){xhr.open("GET",e,!1),xhr.setRequestHeader("Accept","text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8"),xhr.setRequestHeader("Accept-Language","en-US, en; q=0.8, zh-Hans-CN; q=0.5, zh-Hans; q=0.3"),xhr.setRequestHeader("Accept-Encoding","gzip, deflate"),xhr.setRequestHeader("TE","gzip, deflate"),xhr.setRequestHeader("Connection","close"),xhr.setRequestHeader("Cache-Control","no-cache"),xhr.setRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134"),xhr.setRequestHeader("Upgrade-Insecure-Requests","1");try{xhr.send()}catch(e){}}function parseXML(e){var t;return 0===e.parseError.errorCode||(t=e.parseError,showError(["You have error ","reason: "+t.reason,"code: "+(t.errorCode>>>0).toString(16),"filepos: "+t.filepos,"line: "+t.line,"linepos: "+t.linepos,"srcText: "+t.srcText,"url: "+t.url].join("\n")),!1)}function getContent(e){var t,o,r,c,s,i;if(getHTML(e),200===xhr.status){for(document.open(),document.write(xhr.responseText),document.close(),t=document.getElementById("content"),c=t.firstChild;c&&(1!==c.nodeType||"Post"!==c.className);)c=c.nextSibling;if(c){for(i=c.firstChild;i&&"PostHead"!==i.className;)i=i.nextSibling;if(i){for(s=i.getElementsByTagName("h2"),s=s?s[0].innerText:"",t=c.firstChild;t&&"PostContent"!==t.className;)t=t.nextSibling;if(t){for(o=t.childNodes,r=o.length-1;r>=0;--r)(re1.test(o[r].className)||re2.test(o[r].nodeName))&&t.removeChild(o[r]);try{ts.WriteLine("A"+(s+"\r\n"+t.innerText).replace(re3,"\r\n").replace(re4,"")),tsCache.WriteLine(e)}catch(t){showError(t,e)}}}}}}var xhr=function(){for(var e=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"],t=0;t<e.length;t++)try{return WScript.CreateObject(e[t])}catch(e){}WScript.Quit(1)}(),xmlDoc,xmlDoc2,sitemap="https://www.lz13.cn/sitemap.xml",sitemapValue,document=new ActiveXObject("htmlfile"),fso=new ActiveXObject("Scripting.FileSystemObject"),ts,tsLog,tsCache,file="lizhi13.txt",oSelection,oSelection2,nodeLoc,re1=/left_box\d*|blank.*|pager/,re2=/ul|ol/i,re3=/[\r\n][\s\u3000]+/g,re4=/^[\s\u3000]+|\s+$/g,logfile=encodeURIComponent(sitemap)+".log",cachefile="$cache.log",oCache={};try{tsLog=fso.OpenTextFile(logfile,8,!0)}catch(e){WScript.Echo("can not write log file "+logfile),WScript.Quit(2)}try{tsCache=fso.OpenTextFile(cachefile,1,!0)}catch(e){WScript.Echo("can not read cache file "+cachefile),WScript.Quit(2)}for(;!tsCache.AtEndOfStream;)oCache[tsCache.ReadLine()]=1;tsCache.Close();try{tsCache=fso.OpenTextFile(cachefile,8,!0)}catch(e){WScript.Echo("can not write cache file "+cachefile),WScript.Quit(2)}try{ts=fso.OpenTextFile(file,8,!0,-1)}catch(e){showError(e,"can not write file "+file),WScript.Quit(3)}try{if(getHTML(sitemap),200===xhr.status){xmlDoc=xhr.responseXML,null==xmlDoc&&(showError("The content is not a XML.URL="+sitemap),WScript.Quit(4)),parseXML(xmlDoc)||WScript.Quit(5),xmlDoc.setProperty("SelectionLanguage","XPath"),xmlDoc.setProperty("SelectionNamespaces",""),oSelection=xmlDoc.selectNodes("sitemapindex/sitemap/loc/text()");for(var i=0,l=oSelection.length-1;i<l;++i)if(sitemapValue=oSelection.item(i).nodeValue,!oCache[sitemapValue])if(getHTML(sitemapValue),200===xhr.status){if(xmlDoc2=xhr.responseXML,null==xmlDoc2){showError("The Content is not a XML.URL="+sitemapValue);continue}if(!parseXML(xmlDoc2))continue;for(xmlDoc2.setProperty("SelectionLanguage","XPath"),xmlDoc2.setProperty("SelectionNamespaces",'xmlns:t="'+xmlDoc2.documentElement.getAttribute("xmlns")+'"'),oSelection2=xmlDoc2.selectNodes("t:urlset/t:url/t:loc/text()");nodeLoc=oSelection2.nextNode();)if(!oCache[nodeLoc.nodeValue])try{getContent(nodeLoc.nodeValue)}catch(e){}tsCache.WriteLine(sitemapValue)}else showError("status"+xhr.status+"\r\n"+xhr.getAllResponseHeaders())}else showError("status"+xhr.status+"\r\n"+xhr.getAllResponseHeaders())}catch(e){throw showError(e),e}finally{ts.Close(),tsLog.Close(),tsCache.Close()}WScript.Echo("Mission complete."),WScript.Quit(0);
复制代码
|