「sanitize-html」に実際にhtmlタグを削除するように指示するにはどうすればよいですか(コンテンツのみを保持します)?現在、たとえば div セクションを保持するように設定した場合、出力にも次のように書き込まれます<div>some content</div>
- I want only the inside...('some content')
短くするために-タグ、属性などは必要ありません-それらの要素のコンテンツのみ..
var Crawler = require("js-crawler");
var download = require("url-download");
var sanitizeHtml = require('sanitize-html');
var util = require('util');
var fs = require('fs');
new Crawler().configure({depth: 1})
.crawl("http://www.cnn.com", function onSuccess(page) {
var clean = sanitizeHtml(page.body,{
allowedTags: [ 'p', 'em', 'strong','div' ],
});
console.log(clean);
fs.writeFile('sanitized.txt', clean, function (err) {
if (err) throw err;
console.log('It\'s saved! in same location.');
});
console.log(util.inspect(clean, {showHidden: false, depth: null}));
var str = JSON.stringify(clean.toString());
console.log(str);
/*download(page.url, './download')
.on('close', function () {
console.log('One file has been downloaded.');
});*/
});