本帖最后由 flashercs 于 2018-11-29 18:41 编辑
保存为 下载.js
下载的项目参数在最后 ,自己改- (function () {
- var xhr = (function () {
- var aXMLHttpVers = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
- for (var i = 0; i < aXMLHttpVers.length; i++) {
- try {
- return new ActiveXObject(aXMLHttpVers[i]);
- } catch (error) { }
- }
- showError('Can\'t build XMLHTTP automation object.');
- WScript.Quit(1);
- })(),
- fso = new ActiveXObject('Scripting.FileSystemObject'),
- domain = 'https://www.juzimi.com/',
- key,
- arr,
- arrOut = [],
- ts,
- sCache,
- tsCache,
- tsLog,
- file,
- reList = /<a[^>]+href="([^"]+)"[^>]*>([^<>]*)<\/a>/gi,
- reNextPage = /<li[^>]+class="pager-next[^"]*"[^>]*>\s*<a[^>]+href="([^"]+)"[^>]*>下一页<\/a>\s*<\/li>/i,
- reAuthor = /<div[^>]+class="views-field-name"[^>]*>\s*<a[^>]+href="([^"]+)"[^>]*>([^<>]+)<\/a>\s*<\/div>/gi,
- reTid = /<div[^>]+class="views-field-tid">\s*<a[^>]+href="([^"]+)">/gi,
- reContent = /<div class="views-field-phpcode-1">([\S\s]+?)<\/div>(?:\s*<div class="xqjulistwafo">([\S\s]*?)<\/div>)?\s*<div class="views-field-ops">([\S\s]*?)<\/div>/gi,
- reC1 = /<div[^>]+class="view-content"[^>]*>[\S\s]+?<div[^>]+class="view-footer"[^>]*>/i,
- reC2 = /<div[^>]+class="view-content"[^>]*>[\S\s]+?<div[^>]+class="item-list"[^>]*>/i,
- reReplace = /(<span[^>]*>(全文)<\/span>|<[^<>]*>| |\n|\r)+/gi,
- reReplaceOriginal = /<span[^>]*>(原创)<\/span>|<[^<>]*>|( |\n|\r)+/gi,
- oWeek = {
- '本周热门原创': 'https://www.juzimi.com/original/week',
- '最新原创句子': 'https://www.juzimi.com/original/ju',
- '推荐原创句子': 'https://www.juzimi.com/original/recommend'
- },
- oCache = {};
- new ActiveXObject('WScript.Shell').CurrentDirectory = fso.GetParentFolderName(WScript.ScriptFullName);
- try {
- var arrTitle = getHtml(domain + 'writers').split(/<div[^>]+id="block-block-20"[^>]*>|<div[^>]*>按句子\/名言类别:<\/div>|<div[^>]*>按名言内容类型:<\/div>/);
- arrTitle.shift();
- arrTitle[2] = /<div[^>]*>[\S\s]*?<\/div>/.exec(arrTitle[2])[0];
- } catch (e) {
- WScript.Quit(5);
- }
- //Define cache file path
- sCache = fso.GetSpecialFolder(2).Path + '\\' + encodeURIComponent(domain) + '.cache';
- //Read cache
- try {
- tsCache = fso.OpenTextFile(sCache, 1, false);
- while (!tsCache.AtEndOfStream) {
- oCache[tsCache.ReadLine()] = true;
- }
- tsCache.Close();
- } catch (e) {
- // WScript.Echo('Can not read Cache');
- // WScript.Quit(2);
- }
- //Write cache
- try {
- tsCache = fso.OpenTextFile(sCache, 8, true);
- } catch (e) {
- WScript.Echo('Can not write Cache');
- WScript.Quit(3);
- }
- for (var i = 0, l = arguments.length; i < l; ++i) {
- if (oWeek[arguments[i]]) {
- if (oCache[oWeek[arguments[i]]]) continue;
- file = arguments[i] + '.txt';
- try {
- ts = fso.OpenTextFile(file, 8, true);
- } catch (error) {
- showError(error, 'Opening file ' + file);
- continue;
- }
- try {
- getContentOriginal(oWeek[arguments[i]]);
- tsCache.WriteLine(oWeek[arguments[i]]);
- } catch (e) {
- showError(e);
- }
- ts.Close();
- continue;
- }
- for (key in arrTitle) {
- arr = RegExp('<a[^>]+href="([^"]+)"[^>]*>' + arguments[i] + '</a>', 'i').exec(arrTitle[key]);
- if (!arr) {
- // showError('Cannot find ' + arguments[i]);
- continue;
- }
- if (oCache[domain + arr[1]]) break;
- //get nav menu url
- file = arguments[i] + '.txt';
- try {
- ts = fso.OpenTextFile(file, 8, true);
- } catch (error) {
- showError(error, 'Opening file ' + file);
- continue;
- }
- //get list
- try {
- switch (key) {
- case '0':
- getList(domain + arr[1]);
- break;
- case '1':
- getList2(domain + arr[1]);
- break;
- default:
- getContent(domain + arr[1]);
- }
- tsCache.WriteLine(domain + arr[1]);
- } catch (e) {
- showError(e);
- }
- //end list
- ts.Close();
- //end nav menu
- break;
- }
- }
- tsCache.Close();
- WScript.Echo('Mission complete.');
- function getList2(url) {
- var str, arr;
- str = getHtml(url);
- if (!oCache[url]) {
- while (arr = reTid.exec(str)) {
- // arrOut.unshift('--' + arr[2]);
- //get content
- getContent(domain + arr[1]);
- //end content
- }
- tsCache.WriteLine(url);
- }
- //nextpage?
- if (arr = reNextPage.exec(str)) {
- getList2(domain + arr[1]);
- }
- }
- function getList(url) {
- var str, arr;
- str = getHtml(url);
- if (!oCache[url]) {
- while (arr = reAuthor.exec(str)) {
- arrOut.unshift('--' + arr[2]);
- //get content
- getContent(domain + arr[1]);
- arrOut.shift();
- //end content
- }
- tsCache.WriteLine(url);
- }
- //nextpage?
- if (arr = reNextPage.exec(str)) {
- getList(domain + arr[1]);
- }
- }
- function getContent(url) {
- var str0, str, arr;
- try {
- str0 = getHtml(url);
- str = str0.match(reC1)[0];
- } catch (error) {
- str = '';
- }
- if (!oCache[url]) {
- while (arr = reContent.exec(str)) {
- arrOut.unshift((arr[1] + (undefined === arr[2] ? '' : arr[2])).replace(reReplace, ''));
- arrOut.unshift(arr[3].replace(reReplace, '') + '\r\n');
- try {
- ts.WriteLine(arrOut.join(''));
- } catch (error) {
-
- } finally {
- arrOut.shift();
- arrOut.shift();
- }
- }
- tsCache.WriteLine(url);
- }
- //nextpage?
- if (arr = reNextPage.exec(str0)) {
- getContent(domain + arr[1]);
- }
- }
- function getContentOriginal(url) {
- var str,
- str0,
- arr;
- try {
- str0 = getHtml(url);
- str = str0.match(reC2)[0];
- } catch (error) {
- str = '';
- }
- if (!oCache[url]) {
- while (arr = reContent.exec(str)) {
- // arrOut.unshift();
- try {
- ts.WriteLine(arr[3].replace(reReplaceOriginal, '') + '\r\n' + (arr[1] + (undefined === arr[2]) ? '' : arr[2]).replace(reReplaceOriginal, fnRp));
- ts.WriteBlankLines(1);
- } catch (error) {
- // showError(error, 'Writing to file ' + file + ' failed.');
- // throw error;
- }
- }
- tsCache.WriteLine(url);
- }
- //nextpage?
- if (arr = reNextPage.exec(str0)) {
- getContentOriginal(domain + arr[1]);
- }
- }
- function getHtml(URL, cnt) {
- cnt = cnt >>> 0;
- WScript.Sleep(5000);//sleep 10s
- xhr.open('GET', URL, false);
- xhr.send();
- if (200 === xhr.status) {
- return xhr.responseText;
- } else if (403 === xhr.status) {
- WScript.Echo(URL + '\n403:网站拒绝下载服务,请更换IP地址后继续下载。');
- if (cnt < 20) {
- return getHtml(URL, cnt + 1);
- } else {
- ts.Close();
- tsCache.Close();
- WScript.Quit(403);
- }
- }
- showError('fetch URI "' + URL + '" failed.\nstatus: ' + xhr.status);
- return '';
- }
- function fnRp($0) {
- var s = $0.toLowerCase();
- return /<br\s*\/?>|<\/\s*br>/.test(s) ? '\r\n' : '';
- }
- function showError(err, source) {
- WScript.Echo('[object Error]' === Object.prototype.toString.call(err) ?
- [
- err.name,
- 'source: ' + (undefined === source ? '' : source),
- 'number: ' + (err.number >>> 0).toString(16),
- 'equipment: ' + (err.number >> 16 & 0x1FFF),
- 'code: ' + (err.number & 0xFFFF),
- 'Information: ' + err.message
- ].join('\n')
- :
- err);
- }
- })('先秦', '汉朝', '魏晋', '南北朝', '隋唐五代', '宋朝', '元朝', '明朝', '清朝', '近现代', '美国名人', '英国', '法国', '德国', '日本', '俄罗斯', '希腊', '罗马', '意大利', '奥地利', '印度', '书籍名句', '电影台词', '小说摘抄', '散文美句', '动漫语录', '连续剧台词', '古文名句', '爱情', '读书', '励志', '时间', '友情', '诚信', '爱国', '激励', '勤奋', '奉献', '真理', '道德', '理想', '人生', '数学', '英语', '母爱', '劳动', '亲情', '创新', '团结', '童年', '感恩', '目标', '本周热门原创', '最新原创句子', '推荐原创句子');
复制代码
|