-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
36 lines (25 loc) · 1.03 KB
/
fetch.js
File metadata and controls
36 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import got from 'got'
import * as cheerio from 'cheerio'
import { writeFile } from 'fs/promises'
async function* traverseDirectory(baseDirectory) {
console.log(baseDirectory)
const htmlPage = await got(baseDirectory).text()
const $ = cheerio.load(htmlPage)
const linksToDirectoriesToTraverse = []
$('a').each((_index, element) => {
const href = $(element).attr('href')
if (href.startsWith('..') === false && href !== 'README') {
linksToDirectoriesToTraverse.push(href)
}
})
const currentDirectoryReadme = await got('README', { prefixUrl: baseDirectory }).text()
yield currentDirectoryReadme
for (const directoryToTraverse of linksToDirectoriesToTraverse) {
yield* traverseDirectory(baseDirectory + directoryToTraverse)
}
}
const readmeFilesContent = []
for await (const readmeFileContent of traverseDirectory('http://192.168.56.101/.hidden/')) {
readmeFilesContent.push(readmeFileContent)
}
await writeFile('./results.txt', readmeFilesContent.join(''))