Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
@@ -265,6 +265,52 @@ app.get('/ytmp3', async (req, res) => {
|
|
265 |
});
|
266 |
|
267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
/*
|
269 |
ββββββββββββββββββββββββββββββ
|
270 |
ββββββββββββββββββ«β£βββββββββββ
|
|
|
265 |
});
|
266 |
|
267 |
|
268 |
+
|
269 |
+
async function fetchHtml(url) {
|
270 |
+
// Launch browser dengan mode headless
|
271 |
+
const browser = await puppeteer.launch({
|
272 |
+
headless: true,
|
273 |
+
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
274 |
+
});
|
275 |
+
|
276 |
+
// Buat page baru
|
277 |
+
const page = await browser.newPage();
|
278 |
+
|
279 |
+
// Set User Agent untuk menghindari deteksi bot
|
280 |
+
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.3');
|
281 |
+
|
282 |
+
// Navigasi ke URL yang diinginkan
|
283 |
+
await page.goto(url);
|
284 |
+
|
285 |
+
// Tunggu sampai page selesai loading
|
286 |
+
await page.waitForNavigation({ waitUntil: 'networkidle2' });
|
287 |
+
|
288 |
+
// Ambil HTML dari page
|
289 |
+
const html = await page.content();
|
290 |
+
|
291 |
+
// Tutup browser
|
292 |
+
await browser.close();
|
293 |
+
|
294 |
+
// Return HTML
|
295 |
+
return html;
|
296 |
+
}
|
297 |
+
|
298 |
+
app.get('/html', async (req, res) => {
|
299 |
+
try {
|
300 |
+
const { url } = req.query;
|
301 |
+
if (!url) return res.status(400).json({ error: 'Parameter url is required' });
|
302 |
+
let result = await fetchHtml(url);
|
303 |
+
res.send(result);
|
304 |
+
} catch (error) {
|
305 |
+
console.error('Error processing request:', error);
|
306 |
+
res.status(500).json({
|
307 |
+
error: 'Failed to process request\n' + error
|
308 |
+
});
|
309 |
+
}
|
310 |
+
});
|
311 |
+
|
312 |
+
|
313 |
+
|
314 |
/*
|
315 |
ββββββββββββββββββββββββββββββ
|
316 |
ββββββββββββββββββ«β£βββββββββββ
|