-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresidential_random.js
51 lines (40 loc) · 1.52 KB
/
residential_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
// Import Chromium from Playwright
const puppeteer = require('puppeteer');
// Create an anonymous and asynchronous function and call it immediately
(async () => {
// For residential proxy, set the API endpoint as the proxy server
// For country-specific proxy, use different API endpoint
// See https://developers.oxylabs.io/residential-proxies/#random-proxy-entry-nodes
var proxy = 'pr.oxylabs.io:7777';
// Create a variable for launch options
const launchOptions = {
// Set the proxy server to the server variable
args: ['--proxy-server=' + proxy],
// Set additional launch options here
headless: true
};
// Lauch the browser with the launch options
const browser = await puppeteer.launch(launchOptions);
// Use a try-catch-finally to close the browser
try {
// Create a new page
const page = await browser.newPage();
await page.authenticate({
username: 'USERNAME',
password: 'PASSWORD'
});
// This page returns the IP address and other location details
await page.goto('https://ip.oxylabs.io/location');
// 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();
}
})();