-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (49 loc) · 2 KB
/
index.js
File metadata and controls
65 lines (49 loc) · 2 KB
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
// Load the products
const puppeteer = require('puppeteer');
const fs = require('fs');
const logFilePath = 'logs.txt';
if (!fs.existsSync(logFilePath)) {
fs.writeFileSync(logFilePath, '', 'utf8');
}
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
const logToFileAndConsole = (message) => {
console.log(message);
fs.appendFileSync(logFilePath, `${message}\n`, 'utf8');
};
page.on('console', (msg) => {
if (msg.type() === 'error') {
logToFileAndConsole(`Console Error: ${msg.text()}`);
}
});
page.on('pageerror', (error) => {
logToFileAndConsole(`JavaScript Error: ${error.message}`);
});
page.on('response', (response) => {
const status = response.status();
const url = response.url();
if (status !== 200) {
logToFileAndConsole(`API Error: ${status} - ${url}`);
}
});
page.on('requestfailed', (request) => {
logToFileAndConsole(`Request Failed: ${request.url()} - ${request.failure().errorText}`);
});
logToFileAndConsole("Navigating to the home page...");
await page.goto('https://hiutdenim.co.uk/', { waitUntil: 'networkidle2' });
logToFileAndConsole("Waiting for the 'Made to Order' link...");
await page.waitForSelector('a[href="/pages/made-to-order"]');
logToFileAndConsole("Clicking on the 'Made to Order' category...");
await page.click('a[href="/pages/made-to-order"]');
logToFileAndConsole("Navigating to the 'Made to Order Men's' collection...");
await page.goto('https://hiutdenim.co.uk/collections/made-to-order-mens', { waitUntil: 'networkidle2' });
logToFileAndConsole("Waiting for the pagination button...");
await page.waitForSelector(".next");
logToFileAndConsole("Clicking on the 'Next' button...");
await page.click(".next");
logToFileAndConsole("Waiting for the footer section to ensure the page has fully loaded...");
await page.waitForSelector(".copyright-text");
logToFileAndConsole("End of Page");
await browser.close();
})();