Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require("express");
|
| 2 |
+
const axios = require("axios");
|
| 3 |
+
const cheerio = require("cheerio");
|
| 4 |
+
|
| 5 |
+
const app = express();
|
| 6 |
+
const PORT = 7860;
|
| 7 |
+
|
| 8 |
+
// Scraper function for numbers list
|
| 9 |
+
async function scrapeUK(page = 1) {
|
| 10 |
+
const url =
|
| 11 |
+
page === 1
|
| 12 |
+
? "https://getsms.cc/temporary-phone-numbers/UK"
|
| 13 |
+
: `https://getsms.cc/temporary-phone-numbers/UK/${page}`;
|
| 14 |
+
|
| 15 |
+
const { data } = await axios.get(url);
|
| 16 |
+
const $ = cheerio.load(data);
|
| 17 |
+
|
| 18 |
+
const results = [];
|
| 19 |
+
$(".card").each((i, el) => {
|
| 20 |
+
const number = $(el).find("p.p-0.m-0.font-weight-bold").text().trim();
|
| 21 |
+
const timeAgo = $(el).find("p.p-0.m-0.small").text().trim();
|
| 22 |
+
const link = $(el).find("a.btn.btn-primary").attr("href");
|
| 23 |
+
|
| 24 |
+
if (number && timeAgo && link) {
|
| 25 |
+
results.push({
|
| 26 |
+
number,
|
| 27 |
+
timeAgo,
|
| 28 |
+
link: `https://getsms.cc${link}`,
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
return results;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Scraper function for messages
|
| 37 |
+
async function scrapeMessages(number) {
|
| 38 |
+
const url = `https://getsms.cc/info/${number}`;
|
| 39 |
+
const { data } = await axios.get(url);
|
| 40 |
+
const $ = cheerio.load(data);
|
| 41 |
+
|
| 42 |
+
const messages = [];
|
| 43 |
+
|
| 44 |
+
$(".direct-chat-msg").each((i, el) => {
|
| 45 |
+
const from = $(el).find(".direct-chat-name").text().trim();
|
| 46 |
+
const timeAgo = $(el).find("time").text().trim();
|
| 47 |
+
const text = $(el).find(".direct-chat-text").text().trim();
|
| 48 |
+
|
| 49 |
+
// Skip ads/empty messages
|
| 50 |
+
if (from && text) {
|
| 51 |
+
messages.push({ from, timeAgo, text });
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
// Return latest 3 (newest first)
|
| 56 |
+
return messages.slice(-3).reverse();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// Endpoint: UK numbers
|
| 60 |
+
app.get("/uk/:page?", async (req, res) => {
|
| 61 |
+
try {
|
| 62 |
+
const page = parseInt(req.params.page) || 1;
|
| 63 |
+
const numbers = await scrapeUK(page);
|
| 64 |
+
|
| 65 |
+
res.json({
|
| 66 |
+
country: "United Kingdom",
|
| 67 |
+
page,
|
| 68 |
+
count: numbers.length,
|
| 69 |
+
numbers,
|
| 70 |
+
});
|
| 71 |
+
} catch (err) {
|
| 72 |
+
console.error("Error:", err.message);
|
| 73 |
+
res.status(500).json({ error: "Failed to scrape numbers" });
|
| 74 |
+
}
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
// Endpoint: messages
|
| 78 |
+
app.get("/msg/:number", async (req, res) => {
|
| 79 |
+
try {
|
| 80 |
+
const number = req.params.number;
|
| 81 |
+
const messages = await scrapeMessages(number);
|
| 82 |
+
|
| 83 |
+
res.json({
|
| 84 |
+
number,
|
| 85 |
+
count: messages.length,
|
| 86 |
+
messages,
|
| 87 |
+
});
|
| 88 |
+
} catch (err) {
|
| 89 |
+
console.error("Error:", err.message);
|
| 90 |
+
res.status(500).json({ error: "Failed to scrape messages" });
|
| 91 |
+
}
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
// Start server
|
| 95 |
+
app.listen(PORT, () => {
|
| 96 |
+
console.log(`Server running on http://localhost:${PORT}`);
|
| 97 |
+
});
|