-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
74 lines (53 loc) · 1.87 KB
/
express.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import express from "express";
import fs from "fs";
import puppeteer from "puppeteer";
const app = express();
app.get("/", (req, res) => {
res.send("Home");
});
app.get("/insta", (req, res) => {
const url = req.query.url;
(async () => {
const browser = await puppeteer.launch({
executablePath:
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", // Specify the path to Chrome executable
});
const page = await browser.newPage();
try {
await page.goto(url); // Replace with the URL of the website
// Wait for client-side rendering to complete (you can adjust the wait time if needed)
await page.waitForTimeout(5000); // Wait for 5 seconds as an example
// Get the updated HTML content after client-side rendering
const updatedHtml = await page.content();
// =============title=============
const titleRegex = /<title>(.*?)<\/title>/i; // Regular expression to match <title>...</title>
const matchTitle = updatedHtml.toString().match(titleRegex); // This will return an array with matched content
// =============title=============
const regex = /<video\s+[^>]*src=["']([^"']+)["'][^>]*>/i;
const match = updatedHtml.toString().match(regex);
if (match && matchTitle) {
const videoSrc = match[1];
const titleContent = matchTitle[1];
const data = {
status: true,
title: titleContent,
data: videoSrc.replace(/&/g, "&"),
};
res.send(data);
} else {
const data = {
status: false,
};
res.send(data);
}
} catch (error) {
const data = {
status: false,
};
res.send(data);
} finally {
await browser.close();
}
})();
});
app.listen(3000);