Enable Proxies

Overview

This guide shows you how to set up and use proxies with Playwright and AgentQL to avoid bot detection.

What's a proxy

A proxy is a server that acts as an intermediary between your browser and the website you are trying to access. You can use different types of proxies such as residential proxies, data center proxies, and mobile proxies.

When should you use a proxy

There are many scenarios where you might want to use a proxy:

  • Bypass geo-restrictions
  • Access blocked websites in your country
  • Hide your IP address
  • Bypass rate limits
  • Bypass bot detection

How to use a proxy with Playwright

You can set the proxy configuration with Playwright. You can use a HTTP(S) or SOCKS5 proxy with Playwright.

main.py
python
import agentql
from playwright.sync_api import sync_playwright

# Replace with your proxy details
YOUR_PROXY_SERVER = "http://your-proxy-server:port"
YOUR_PROXY_USERNAME = "your-proxy-username"
YOUR_PROXY_PASSWORD = "your-proxy-password"

with sync_playwright() as playwright:
    # Launch browser with proxy settings
    browser = playwright.chromium.launch(
        proxy={
            "server": YOUR_PROXY_SERVER,
            "username": YOUR_PROXY_USERNAME,
            "password": YOUR_PROXY_PASSWORD,
        }
    )
    
    # Wrap browser with AgentQL
    page = agentql.wrap(browser.new_page())
    page.goto("https://example.com")
    
    # Output the page title
    print(page.title())

    # Add your own code here

You'll need to replace YOUR_PROXY_SERVER, YOUR_PROXY_USERNAME, and YOUR_PROXY_PASSWORD with your actual proxy details.

The proxy argument within the playwright.chromium.launch() function is responsible for establishing the proxy configuration, which includes the proxy server URL along with the port, and the credentials necessary for authentication.

To learn more about proxies with Playwright, see Playwright Proxy.

Conclusion

In this guide, you learned how to set up and use proxies with Playwright while integrating it with AgentQL. Using proxies is a common way to avoid bot detection.