-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.js
33 lines (31 loc) · 948 Bytes
/
parser.js
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
"use strict";
const http = require('http');
const htmlparser = require('htmlparser2');
const hostname = 'www.sinfest.net';
function ParseTitlePage(callback) {
const parser = new htmlparser.Parser({
onopentag: (name, attr) => {
if (name === 'img' && attr.src.indexOf('btphp') !== -1) {
console.log(`Parsed url:${attr.src}`);
callback(hostname + '/' + attr.src);
}
}
}, {
decodeEntities: true
});
const options = {
hostname: 'www.sinfest.net',
path: '/index.php',
method: 'GET',
headers: {
'user-agent': 'Mozilla/5.0'
}
};
let data = '';
http.get(options, (res) => {
res.on('data', (chunk) => parser.write(chunk))
.on('end', () => parser.end())
}).on('error', (e) => console.error(e));
}
//ParseTitlePage((url) => console.log(url))
module.exports = ParseTitlePage;