x
This commit is contained in:
1 parent
fb776f778f
commit
8f64d89f6f
13 files changed
+779
-295
No files matched your search
@@ -0,0 +1,31 @@
|
||||
const cheerio = require('cheerio');
|
||||
const fs = require('fs');
|
||||
const html = fs.readFileSync('mega01.html', 'utf8');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
console.log('--- Page Title ---');
|
||||
console.log($('title').text());
|
||||
|
||||
console.log('\n--- Main Content Sections ---');
|
||||
const sections = [];
|
||||
$('section, .section, [data-section]').each((i, el) => {
|
||||
sections.push({
|
||||
index: i + 1,
|
||||
id: $(el).attr('id') || 'no-id',
|
||||
class: $(el).attr('class') || 'no-class',
|
||||
text: $(el).text().replace(/\s+/g, ' ').substring(0, 500)
|
||||
});
|
||||
});
|
||||
if (sections.length === 0) {
|
||||
// If no semantic tags, maybe just print divs with specific classes
|
||||
$('div').each((i, el) => {
|
||||
if($(el).attr('class') && $(el).attr('class').includes('py-')) {
|
||||
sections.push({
|
||||
index: i + 1,
|
||||
class: $(el).attr('class') || 'no-class',
|
||||
text: $(el).text().replace(/\s+/g, ' ').substring(0, 500)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log(JSON.stringify(sections, null, 2));
|
||||
Reference in new issue
Block a user