@
@xemoz8 files
Published 25 minutes ago
javascript
KOMIKU SCRAPER
scrape komiku
Auto-Detected Dependencies
axioscheerio
$ npm install axios cheeriodetail.jsjavascript· 124 lines · 4.1 KB
const axios = require('axios');
const cheerio = require('cheerio');
const BASE = 'https://komiku.org';
const HEADERS = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'id-ID,id;q=0.9,en;q=0.8'
};
module.exports = {
path: '/komik/komiku/detail?apikey=&url=',
name: 'Komiku Detail',
id: 'detail',
category: 'Komik',
params: [
{
name: 'url',
required: true,
example: 'https://komiku.org/manga/from-goblin-to-goblin-god/',
description: 'URL lengkap halaman komik di Komiku',
},
],
desc: 'Ambil detail informasi dan daftar chapter komik.',
async run(req, res) {
const url = String(req.query.url || req.body.url || '').trim();
if (!url) return res.status(400).json({ status: false, message: 'Parameter url diperlukan' });
if (!url.startsWith(BASE)) {
return res.status(400).json({ status: false, message: 'URL tidak valid' });
}
try {
const { data: html } = await axios.get(url, { headers: HEADERS, timeout: 30000 });
const $ = cheerio.load(html);
const thumbnail = $('.ims img').attr('src');
const judul = $('h1 span').text().trim();
const judulAlternatif = $('.j2').text().trim();
const tipe = $('.inftable td').eq(5).text().trim();
const tema = $('.inftable td').eq(7).text().trim();
const genre = [];
$('.genre li a span').each((i, el) => {
genre.push($(el).text().trim());
});
const author = $('.inftable td').eq(11).text().trim();
const status = $('.inftable td').eq(13).text().trim();
const rating = $('.inftable td').eq(15).text().trim();
const caraBaca = $('.inftable td').eq(19).text().trim();
const sinopsis = $('.desc').text().trim();
const pembacaText = $('.inftable td').eq(17).text().trim();
let totalViews = '';
let weeklyViews = '';
if (pembacaText) {
const matchTotal = pembacaText.match(/Total:\s*([\d,.]+(rb|jt)?)/);
const matchWeekly = pembacaText.match(/Minggu ini:\s*([\d,.]+)/);
totalViews = matchTotal ? matchTotal[1] : '';
weeklyViews = matchWeekly ? matchWeekly[1] : '';
}
let datePublished = '';
let dateModified = '';
const jsonLdMatch = html.match(/<script type="application\/ld\+json">([\s\S]*?)<\/script>/);
if (jsonLdMatch) {
try {
const jsonData = JSON.parse(jsonLdMatch[1]);
if (jsonData['@graph']) {
const webpage = jsonData['@graph'].find(item => item['@type'] === 'WebPage');
if (webpage) {
datePublished = webpage.datePublished || '';
dateModified = webpage.dateModified || '';
}
}
} catch (e) {}
}
const chapters = [];
$('#Daftar_Chapter tbody tr').each((i, el) => {
const chapterLink = $(el).find('td.judulseries a').attr('href');
const chapterTitle = $(el).find('td.judulseries a span').text().trim();
const date = $(el).find('td.tanggalseries').text().trim();
if (chapterLink && chapterTitle) {
chapters.push({
title: chapterTitle,
url: BASE + chapterLink,
date
});
}
});
return res.json({
status: true,
result: {
url,
thumbnail,
judul,
judul_alternatif: judulAlternatif,
tipe,
tema,
genre,
author,
status,
rating,
cara_baca: caraBaca,
total_views: totalViews,
weekly_views: weeklyViews,
sinopsis,
date_published: datePublished,
date_modified: dateModified,
total_chapter: chapters.length,
chapters
}
});
} catch (err) {
return res.status(500).json({ status: false, message: err.message });
}
}
};