Playwright

Playwright

This guide provides instructions on how to integrate Evomi’s proxies with Playwright, a popular automation library for web browsers.

Prerequisites

Before you begin, ensure you have the following:

  1. Node.js or Python installed on your system
  2. Playwright installed in your project
  3. Your Evomi proxy credentials (username and password)

Installation

If you haven’t already installed Playwright, you can do so using npm (for JavaScript) or pip (for Python):

For JavaScript:

npm install playwright

For Python:

pip install playwright

Configuration

To use Evomi proxies with Playwright, you need to configure the browser context with the proxy settings. Here’s how you can do it in both JavaScript and Python:

JavaScript Example

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    proxy: {
      server: 'http://rp.evomi.com:1000',
      username: 'your_username',
      password: 'your_password_session-anychars_mode-speed'
    }
  });

  const page = await context.newPage();
  await page.goto('https://ip.evomi.com/s');
  const content = await page.content();
  console.log(content);

  await browser.close();
})();

Python Example

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
        proxy={
            "server": "http://rp.evomi.com:1000",
            "username": "your_username",
            "password": "your_password_session-anychars_mode-speed"
        }
    )
    
    page = context.new_page()
    page.goto("https://ip.evomi.com/s")
    content = page.content()
    print(content)
    
    browser.close()

Replace your_username and your_password_session-anychars_mode-speed with your actual Evomi proxy credentials.

Explanation

Let’s break down the key parts of these scripts:

  1. We import the necessary modules from Playwright.
  2. We launch a new browser instance.
  3. We create a new browser context with proxy settings:
    • server: This is set to the appropriate Evomi proxy endpoint (see below for different product endpoints).
    • username and password: These should be your Evomi proxy credentials.
  4. We create a new page in this context and navigate to https://ip.evomi.com/s to verify the proxy connection.
  5. We print the page content, which should show the IP address of the proxy you’re using.
  6. Finally, we close the browser.

Evomi Proxy Endpoints

Depending on the Evomi product you’re using, you’ll need to adjust the proxy server address in your code. Here are the endpoints for different Evomi products:

Residential Proxies

  • HTTP Proxy: rp.evomi.com:1000
  • HTTPs Proxy: rp.evomi.com:1001
  • SOCKS5 Proxy: rp.evomi.com:1002

Mobile Proxies

  • HTTP Proxy: mp.evomi.com:3000
  • HTTPs Proxy: mp.evomi.com:3001
  • SOCKS5 Proxy: mp.evomi.com:3002

Datacenter Proxies

  • HTTP Proxy: dcp.evomi.com:2000
  • HTTPs Proxy: dcp.evomi.com:2001
  • SOCKS5 Proxy: dcp.evomi.com:2002

To use a different product or protocol, simply replace the server address in your code with the appropriate endpoint and port from the list above.

Running the Script

For JavaScript, save the script to a file (e.g., proxy_test.js) and run it using Node.js:

node proxy_test.js

For Python, save the script to a file (e.g., proxy_test.py) and run it using Python:

python proxy_test.py

If everything is set up correctly, you should see the content of https://ip.evomi.com/s printed in your console, showing the IP address of the Evomi proxy you’re using.

Tips and Troubleshooting

  • If you’re having connection issues, double-check your proxy credentials and make sure you’re using the correct endpoint and port for your chosen product.
  • Remember to handle errors appropriately in your production code, as network requests can fail for various reasons.

By following this guide, you should now be able to successfully integrate Evomi’s proxies with your Playwright scripts for web automation and scraping tasks.