-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt.ts
20 lines (16 loc) · 954 Bytes
/
txt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// import modules
import fs from 'fs';
import { JSDOM } from 'jsdom';
// функция для чтения и обработки HTML файла
async function extractPAndSaveToFile({ htmlFilePath, outputFilePath }: { htmlFilePath: string; outputFilePath: string; }) {
const htmlContent = fs.readFileSync(htmlFilePath, 'utf8');
const dom = new JSDOM(htmlContent);
const paragraphs = dom.window.document.querySelectorAll('p');
const combinedText = Array.from(paragraphs).map(p => p.textContent).join('\n');
fs.writeFileSync(outputFilePath, combinedText, 'utf8');
console.log(`Data extracted and saved to ${outputFilePath}`);
}
// Пример использования функции
const htmlFilePath = 'data/html/102041891.html'; // Путь к вашему HTML файлу
const outputFilePath = 'output.txt'; // Путь к файлу для сохранения
extractPAndSaveToFile({ htmlFilePath, outputFilePath });