-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (74 loc) · 2.62 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import chalk from 'chalk';
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import { executablePath } from 'puppeteer';
puppeteer.use(StealthPlugin());
const args = process.argv;
let [,, url] = args;
if (!url) {
console.log(`${chalk.bgRed('ERROR:')} Url is absent`)
process.exit(1);
}
url = url.trim().toLowerCase();
if (!/^(http|https):\/\/[^ "]+$/.test(url.trim())) {
console.log(`${chalk.bgRed('ERROR:')} Invalid format of url`)
process.exit(1);
}
(async () => {
const browser = await puppeteer.launch({ executablePath: executablePath() });
const page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
{
brands: [
{
brand: "Chromium",
version: "110",
},
{
brand: "Not A(Brand",
version: "24",
},
{
brand: "Google Chrome",
version: "110",
}
],
platform: "Windows",
platformVersion: "10.0.0",
architecture: "x86",
model: "x64",
mobile: false,
});
await page.setRequestInterception(true);
page.on('console', msg => console.log(msg.text()));
page.on('request', async (request) => {
let headers;
if (request.url().endsWith('api.php')) {
await page.setExtraHTTPHeaders({'referer': 'https://dev.amidstyle.com/'});
headers = request.headers();
headers["sec-fetch-dest"] = "empty";
headers["sec-fetch-mode"] = "cors";
headers["sec-fetch-site"] = "same-origin";
}
await request.continue({headers})
});
page.on('response', async (response) => {
if (response.url().endsWith('/api.php')) {
// Here I can retrieve content of the div#data using await response.text();
setTimeout(getElement, 1000);
}
});
await page.goto(url, {waitUntil: 'load'});
await page.evaluate(async () => {
const newProto = navigator.__proto__;
delete newProto.webdriver;
navigator.__proto__ = newProto;
});
await page.screenshot({'path': 'admidstyle.png'})
const getElement = async () => {
let element = await page.$('div#data');
let value = await page.evaluate(el => el.textContent, element);
console.log(JSON.parse(value));
await browser.close();
}
})();