File size: 10,683 Bytes
0fe515c 4ca25f0 0fe515c 8b3d448 0fe515c 4ca25f0 0fe515c 4ca25f0 32d4856 8b3d448 4ca25f0 0fe515c 32d4856 b483071 32d4856 8b3d448 32d4856 8b3d448 b483071 8b3d448 b483071 8b3d448 b483071 8b3d448 b483071 8b3d448 b483071 1a6e182 b483071 8b3d448 b483071 8b3d448 1a6e182 b483071 8b3d448 1a6e182 b483071 1a6e182 b483071 1a6e182 b483071 8b3d448 b483071 8b3d448 b483071 8b3d448 b483071 1a6e182 b483071 1a6e182 8b3d448 4ca25f0 0fe515c 4ca25f0 0fe515c 4ca25f0 0fe515c 4ca25f0 0fe515c 4ca25f0 0fe515c de22469 0fe515c 4ca25f0 32d4856 4ca25f0 32d4856 4ca25f0 0fe515c 4ca25f0 0fe515c | 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | const express = require("express");
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
const cheerio = require("cheerio");
require('dotenv').config();
// Add stealth plugin
puppeteer.use(StealthPlugin());
const app = express();
const PORT = 7860;
// Browser instance management
let browser = null;
let authenticatedPage = null;
let isLoggedIn = false;
async function getBrowser() {
if (!browser) {
browser = await puppeteer.launch({
headless: "new", // Use new headless mode
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
'--disable-gpu',
'--disable-web-security',
'--disable-features=VizDisplayCompositor'
]
});
}
return browser;
}
// Get or create authenticated page
async function getAuthenticatedPage() {
if (!authenticatedPage || authenticatedPage.isClosed()) {
const browser = await getBrowser();
authenticatedPage = await setupPage(browser);
isLoggedIn = false; // Reset login status for new page
}
return authenticatedPage;
}
// Login function with extensive debugging
async function performLogin() {
if (isLoggedIn) return true;
const page = await getAuthenticatedPage();
try {
console.log('Performing login...');
console.log('Using email:', process.env.LOGIN_EMAIL ? 'Found' : 'Missing');
console.log('Using password:', process.env.LOGIN_PASSWORD ? 'Found' : 'Missing');
// Navigate to login page
await page.goto('https://getsms.cc/auth/login', {
waitUntil: 'networkidle2',
timeout: 30000
});
console.log('Loaded login page');
// Wait for form to be visible
await page.waitForSelector('form#login', { timeout: 10000 });
console.log('Found login form');
// Take screenshot before login (for debugging)
// await page.screenshot({ path: 'before-login.png' });
// Clear and fill email field
await page.evaluate(() => {
const emailField = document.querySelector('input[name="mail"]');
if (emailField) emailField.value = '';
});
await page.focus('input[name="mail"]');
await page.type('input[name="mail"]', process.env.LOGIN_EMAIL, { delay: 50 });
// Clear and fill password field
await page.evaluate(() => {
const passwordField = document.querySelector('input[name="password"]');
if (passwordField) passwordField.value = '';
});
await page.focus('input[name="password"]');
await page.type('input[name="password"]', process.env.LOGIN_PASSWORD, { delay: 50 });
console.log('Filled login form');
// Wait a moment before submitting
await new Promise(resolve => setTimeout(resolve, 1000));
// Submit form with different approach
await page.evaluate(() => {
const form = document.querySelector('form#login');
if (form) {
form.submit();
}
});
console.log('Submitted form, waiting for response...');
// Wait for either navigation or page update
try {
await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 15000 });
console.log('Navigation detected');
} catch (e) {
console.log('No navigation, checking for page updates...');
await new Promise(resolve => setTimeout(resolve, 3000));
}
const currentUrl = page.url();
console.log('Current URL after login attempt:', currentUrl);
// Take screenshot after login (for debugging)
// await page.screenshot({ path: 'after-login.png' });
// Check for error messages on the page
const errorMessage = await page.evaluate(() => {
const errorElements = document.querySelectorAll('.alert-danger, .text-danger, .error, .alert-error');
for (let el of errorElements) {
if (el.textContent.trim()) {
return el.textContent.trim();
}
}
return null;
});
if (errorMessage) {
console.log('Login error message:', errorMessage);
return false;
}
// More comprehensive login success check
const loginCheck = await page.evaluate(() => {
const url = window.location.href;
const bodyText = document.body.innerText.toLowerCase();
// Check various indicators of successful login
const indicators = {
notOnLoginPage: !url.includes('/auth/login'),
hasLogoutLink: document.querySelector('[href*="logout"]') !== null,
hasUserDropdown: document.querySelector('.dropdown-toggle') !== null,
hasUserProfile: document.querySelector('.user-profile') !== null,
hasDashboard: bodyText.includes('dashboard'),
hasWelcome: bodyText.includes('welcome'),
hasMyAccount: bodyText.includes('my account'),
urlIndicatesSuccess: url.includes('/dashboard') || url.includes('/account') || url === 'https://getsms.cc/'
};
console.log('Login indicators:', indicators);
return {
success: Object.values(indicators).some(v => v),
indicators,
url,
pageTitle: document.title
};
});
console.log('Login check result:', loginCheck);
if (loginCheck.success) {
isLoggedIn = true;
console.log('✅ Login successful - authenticated session established');
return true;
} else {
console.log('❌ Login failed - no success indicators found');
// Get page content for debugging
const pageContent = await page.evaluate(() => {
return document.body.innerText.substring(0, 1000);
});
console.log('Page content after login:', pageContent);
return false;
}
} catch (error) {
console.error('Login error:', error);
return false;
}
}
// Enhanced page setup for maximum stealth
async function setupPage(browser) {
const page = await browser.newPage();
// Set viewport to common resolution
await page.setViewport({ width: 1366, height: 768 });
// Set realistic user agent
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
// Set additional headers
await page.setExtraHTTPHeaders({
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'DNT': '1',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
});
return page;
}
// Scraper function for numbers list with stealth
async function scrapeUK(pageNum = 1) {
const browser = await getBrowser();
const page = await setupPage(browser);
try {
const url = pageNum === 1
? "https://getsms.cc/temporary-phone-numbers/UK"
: `https://getsms.cc/temporary-phone-numbers/UK/${pageNum}`;
// Navigate with realistic options
await page.goto(url, {
waitUntil: 'networkidle2',
timeout: 30000
});
// Add random delay to mimic human behavior
await new Promise(resolve => setTimeout(resolve, Math.random() * 2000 + 1000));
// Get page content
const content = await page.content();
const $ = cheerio.load(content);
const results = [];
$(".card").each((i, el) => {
const number = $(el).find("p.p-0.m-0.font-weight-bold").text().trim();
const timeAgo = $(el).find("p.p-0.m-0.small").text().trim();
const link = $(el).find("a.btn.btn-primary").attr("href");
if (number && timeAgo && link) {
results.push({
number,
timeAgo,
link: `https://getsms.cc${link}`,
});
}
});
return results;
} catch (error) {
console.error('Error scraping UK numbers:', error);
throw error;
} finally {
await page.close();
}
}
// Scraper function for messages with stealth
async function scrapeMessages(number) {
const browser = await getBrowser();
const page = await setupPage(browser);
try {
const url = `https://getsms.cc/info/${number}`;
// Navigate with realistic options
await page.goto(url, {
waitUntil: 'networkidle2',
timeout: 30000
});
// Add random delay
await new Promise(resolve => setTimeout(resolve, Math.random() * 2000 + 1000));
// Get page content
const content = await page.content();
const $ = cheerio.load(content);
const messages = [];
$(".direct-chat-msg").each((i, el) => {
const from = $(el).find(".direct-chat-name").text().trim();
const timeAgo = $(el).find("time").text().trim();
const text = $(el).find(".direct-chat-text").text().trim();
// Skip ads/empty messages
if (from && text) {
messages.push({ from, timeAgo, text });
}
});
// Return latest 3 (newest first)
return messages.slice(-3).reverse();
} catch (error) {
console.error('Error scraping messages:', error);
throw error;
} finally {
await page.close();
}
}
// Endpoint: UK numbers
app.get(["/uk", "/uk/:page"], async (req, res) => {
try {
const page = parseInt(req.params.page) || 1;
const numbers = await scrapeUK(page);
res.json({
country: "United Kingdom",
page,
count: numbers.length,
numbers,
});
} catch (err) {
console.error("Error:", err.message);
res.status(500).json({ error: "Failed to scrape numbers" });
}
});
// Endpoint: messages
app.get("/msg/:number", async (req, res) => {
try {
const number = req.params.number;
const messages = await scrapeMessages(number);
res.json({
number,
count: messages.length,
messages,
});
} catch (err) {
console.error("Error:", err.message);
res.status(500).json({ error: "Failed to scrape messages" });
}
});
// Graceful shutdown
process.on('SIGINT', async () => {
console.log('Shutting down gracefully...');
if (authenticatedPage && !authenticatedPage.isClosed()) {
await authenticatedPage.close();
}
if (browser) {
await browser.close();
}
process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('Shutting down gracefully...');
if (authenticatedPage && !authenticatedPage.isClosed()) {
await authenticatedPage.close();
}
if (browser) {
await browser.close();
}
process.exit(0);
});
// Start server
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
console.log('Using Puppeteer with stealth mode to avoid detection');
}); |