Created
December 8, 2018 09:53
-
-
Save Foair/c4d4513fb624d99f4bcbbd34a3323b3c to your computer and use it in GitHub Desktop.
VCB-Studio 开放课程文档递归获得下载地址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require('axios'); | |
| const fs = require('fs'); | |
| axios.defaults.baseURL = 'https://vcb-s.nmm-hd.org'; | |
| const visitedLinks = []; | |
| const files = []; | |
| async function getURL(url) { | |
| if (visitedLinks.includes(url)) return; | |
| else visitedLinks.push(url); | |
| console.log('>>>', url); | |
| const body = { | |
| action: 'get', | |
| items: { | |
| href: url, | |
| what: 1 | |
| } | |
| }; | |
| const { | |
| data: { items } | |
| } = await axios.post(url + '?', body); | |
| items | |
| .filter(i => i.fetched === undefined) | |
| .map(i => { | |
| files.push(i.href); | |
| }); | |
| items.filter(i => i.fetched === false).map(i => getURL(i.href)); | |
| } | |
| getURL('/'); | |
| setTimeout(() => { | |
| fs.writeFileSync('url.txt', files.reduce((a, b) => `${a}\n${b}`)); | |
| }, 100000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require('axios'); | |
| const fs = require('fs'); | |
| const baseURL = 'https://vcb-s.nmm-hd.org'; | |
| axios.defaults.baseURL = baseURL; | |
| const visitedLinks = []; | |
| const files = []; | |
| async function getURL(url, first = false) { | |
| if (visitedLinks.includes(url)) return; | |
| else visitedLinks.push(url); | |
| console.log('>>>', decodeURI(url)); | |
| const body = { | |
| action: 'get', | |
| items: { | |
| href: url, | |
| what: 1 | |
| } | |
| }; | |
| const { | |
| data: { items } | |
| } = await axios.post(url + '?', body); | |
| let file = items.filter(i => i.fetched === undefined); | |
| if (!first) | |
| file = file.filter(i => !['/Menu.xlsx', '/readme.txt'].includes(i.href)); | |
| file.map(i => { | |
| files.push(i.href); | |
| }); | |
| return Promise.all( | |
| items.filter(i => i.fetched === false).map(i => getURL(i.href)) | |
| ); | |
| } | |
| getURL('/', true).then(() => { | |
| fs.writeFileSync('url.txt', files.map(i => baseURL + i).join('\n')); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Node 执行
vcb-b.js控制台输出结果如下: