-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaywright.js
43 lines (34 loc) · 1.25 KB
/
playwright.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
const { chromium } = require('playwright');
(async () => {
// Proxy server
const proxy = 'gate.smartproxy.com:10001';
// Launch a new browser instance with proxy settings
const browser = await chromium.launch({
headless: false,
proxy: {
server: `http://${proxy}`,
},
});
// Open a new browser context and pass the credentials
const context = await browser.newContext({
httpCredentials: {
username: 'user',
password: 'pass',
},
});
// Open a single page
const page = await context.newPage();
// Check IP on the same page by navigating to the IP check URL
await page.goto('https://ip.smartproxy.com/ip');
const content = await page.evaluate(() => document.body.innerText);
console.log(`Your IP: ${content}`);
// Navigate to the ScrapeMe website
await page.goto('https://scrapeme.live/shop/');
// Select all elements matching the class
const productElements = await page.$$('.woocommerce-loop-product__title');
// Access the 3rd element (index 2) and get its text content
const thirdProductTitle = await productElements[2].textContent();
console.log(`3rd Product Title: ${thirdProductTitle}`);
// Close the browser
await browser.close();
})();