-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (53 loc) · 1.6 KB
/
index.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
import puppeteer from 'puppeteer';
import fs from 'fs/promises'; // Use fs/promises for async file reading
import { setTimeout } from 'timers/promises';
import chromium from "@sparticuz/chromium";
async function loadCookies(filePath) {
try {
const cookiesJSON = await fs.readFile(filePath, 'utf-8');
return JSON.parse(cookiesJSON);
} catch (error) {
console.error('Error reading cookies:', error);
return [];
}
}
const launchProdConfig = {
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
};
async function run() {
const browser = await puppeteer.launch(launchProdConfig);
const page = await browser.newPage();
// Load cookies from the file
const cookies = await loadCookies('./cookies.json');
if (cookies.length > 0) {
await page.setCookie(...cookies);
console.log('Cookies Loaded!');
} else {
console.log('No cookies loaded');
}
const targetUrl = 'https://www.dubaievisaservices.com/visa/applyVisa.jsf';
while (true) {
try {
// Navigate to the target URL
await page.goto(targetUrl, { waitUntil: 'networkidle0' });
if (page.url().includes('login')) {
console.log('Session Expired');
// await browser.close()
// break;
} else {
console.log('Page reloaded');
}
// Wait for 5 minutes (300,000 milliseconds)
await setTimeout(300000);
} catch (error) {
console.log('Error during page reload:', error);
await browser.close()
break;
}
}
}
run();