-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatacenter_random.js
59 lines (46 loc) · 1.57 KB
/
datacenter_random.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
// Import Chromium from Playwright
const puppeteer = require('puppeteer');
// Array that contains the proxy servers
let proxies = [
'20.94.229.106:80',
'209.141.55.228:80',
'103.149.162.194:80',
'206.253.164.122:80'
];
// Create an anonymous and asynchronous function and call it immediately
(async () => {
// Randomly select a proxy from the array
var proxy = proxies[Math.floor(Math.random() * proxies.length)];
// Create a variable for launch options
const launchOptions = {
// Set the proxy server to the proxy
args: ['--proxy-server=' + proxy],
// Set additional launch options here
headless: false
};
// Lauch the browser with the launch options
const browser = await puppeteer.launch(launchOptions);
// Use a try-catch-finally to ensure that browser is closed
try {
// Create a new page
const page = await browser.newPage();
// Set the username and password provided by Oxylabs
await page.authenticate({
username: 'USERNAME',
password: 'PASSWORD'
});
// This page simply returns the IP address
await page.goto('https://httpbin.org/ip');
// Print the response from the page
// This will print the IP address of the proxy
const extractedText = await page.$eval('*', (el) => el.innerText);
console.log(extractedText);
} catch (e) {
// print the error to the console
console.log(e);
}
finally {
// Close the browser
await browser.close();
}
})();