26 lines
749 B
JavaScript
26 lines
749 B
JavaScript
const fs = require('fs');
|
|
const html = fs.readFileSync('/home/x79/sisvietnamvn_01/BV_DHYD_HCM/Các chuyên khoa tại Bệnh viện Đại học Y Dược TP. Hồ Chí Minh.html', 'utf8');
|
|
|
|
let imgCount = 0;
|
|
let idx = 0;
|
|
while (true) {
|
|
idx = html.indexOf('<img', idx);
|
|
if (idx === -1) break;
|
|
|
|
const endIdx = html.indexOf('>', idx);
|
|
const tag = html.substring(idx, endIdx + 1);
|
|
|
|
// get parent context 100 chars before
|
|
const ctxBefore = html.substring(Math.max(0, idx - 100), idx);
|
|
|
|
if (ctxBefore.includes('chuyen-khoa')) {
|
|
console.log('Context:', ctxBefore);
|
|
console.log('Tag:', tag);
|
|
console.log('---');
|
|
imgCount++;
|
|
}
|
|
|
|
idx = endIdx;
|
|
if (imgCount > 5) break;
|
|
}
|