> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/es/agent-browser/geolocation-and-proxy-selection.md).

# Geolocalización y selección de proxy

Descubre cómo usar los parámetros de ubicación de Oxylabs Agent Browser para acceder a datos web desde ubicaciones específicas.

Usa parámetros de geolocalización y enrutamiento de proxy directamente en la URL de conexión WebSocket para enrutar tus sesiones automatizadas de Agent Browser a través de regiones geográficas específicas y controlar el uso de tu IP de proxy.

## Parámetros de geolocalización

Puedes orientar ubicaciones geográficas específicas por país, estado o ciudad usando tres parámetros de consulta principales.

### País

<table data-header-hidden><thead><tr><th width="90"></th><th></th></tr></thead><tbody><tr><td><code>p_cc</code></td><td>Código de país de 2 letras (p. ej., <code>US</code>, <code>DE</code>, <code>FR</code>). Si no se especifica un país, se asigna automáticamente según la disponibilidad.</td></tr></tbody></table>

```
wss://USER:PASS@hb.oxylabs.io?p_cc=US
```

### Ciudad

<table data-header-hidden><thead><tr><th width="90"></th><th></th></tr></thead><tbody><tr><td><code>p_city</code></td><td>Nombre de la ciudad escrito en minúsculas (p. ej., <code>berlin</code>, <code>los_angeles</code>). También debes especificar <code>p_cc</code> o <code>p_state</code>.</td></tr></tbody></table>

```
wss://USER:PASS@hb.oxylabs.io?p_cc=US&p_city=new_york
```

{% hint style="info" %}
La segmentación a nivel de ciudad funciona como una *preferencia de mejor esfuerzo*. Si el pool de proxies residenciales no tiene un proxy disponible en la ubicación exacta solicitada, cambia automáticamente al ámbito del país.
{% endhint %}

### Estado (solo EE. UU.)

<table data-header-hidden><thead><tr><th width="90"></th><th></th></tr></thead><tbody><tr><td><code>p_state</code></td><td>Nombre del estado de EE. UU. en minúsculas (p. ej., <code>texas</code>, <code>ohio</code>). Consulta la lista completa de <a href="https://content.gitbook.com/content/BQ7Zf9paoN3FTeGcyfY1/blobs/cVjpiu1GKicluiVIT9og/us_states.txt">estados compatibles</a>.</td></tr></tbody></table>

```
wss://USER:PASS@hb.oxylabs.io?p_state=texas&p_city=houston
```

{% hint style="info" %}
**Nota:** Si `p_state` y `p_cc` se especifican ambos, `p_state` tiene prioridad y `p_cc` se ignora.
{% endhint %}

## Selección de proxy (proxies persistentes)

De forma predeterminada, el gateway de proxy asigna una IP de salida nueva a cada sesión única de conexión del navegador. Como alternativa, puedes fijar una IP de salida residencial específica en intentos continuos de conexión del navegador incluyendo los `proxy_resi_ses_id` y `proxy_resi_ses_time` parámetros.

<table><thead><tr><th width="181">Parámetro</th><th width="479">Descripción</th><th width="83">Tipo</th></tr></thead><tbody><tr><td><code>proxy_resi_ses_id</code></td><td>Nombre alfanumérico del identificador de sesión de 3 a 36 caracteres.</td><td>cadena</td></tr><tr><td><code>proxy_resi_ses_time</code></td><td>Cantidad de minutos para mantener la IP de salida del proxy residencial fijada. Mín. – 1 minuto, máx. – 1440 minutos (24 horas).</td><td>entero</td></tr></tbody></table>

```bash
# Example: Pin a US-based IP for 60 minutes
wss://USER:PASS@hb.oxylabs.io?p_cc=US&proxy_resi_ses_id=unique_job_id_101&proxy_resi_ses_time=60
```

{% hint style="warning" %}
Para mantener exactamente la misma IP de salida en conexiones consecutivas, debes pasar valores idénticos para ambos `proxy_resi_ses_id` y `proxy_resi_ses_time` en cada cadena URL posterior.
{% endhint %}

## Ejemplos de código

Los siguientes ejemplos muestran cómo construir cadenas de conexión que aplican segmentación geográfica junto con restricciones de IP de proxy residencial persistente.

{% tabs %}
{% tab title="Python (Playwright)" %}

```python
from playwright.sync_api import sync_playwright

username = "USERNAME_abc12"
password = "PASSWORD"
endpoint = "hb.oxylabs.io"

# Target New York city and pin the residential IP for 30 minutes
geolocation = "p_cc=US&p_city=new_york"
sticky_proxy = "proxy_resi_ses_id=scrape_session_404&proxy_resi_ses_time=30"
browser_url = f"wss://{username}:{password}@{endpoint}?{geolocation}&{sticky_proxy}"

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(browser_url)
    page = browser.new_page()
    page.goto("https://ip.oxylabs.io/location")
    print(page.title())
    browser.close()
```

{% endtab %}

{% tab title="JavaScript (Playwright)" %}

```javascript
import { chromium } from "playwright";

const username = "USERNAME_abc12";
const password = "PASSWORD";
const endpoint = "hb.oxylabs.io";

// Target Texas state and pin the residential IP for 60 minutes
const geolocation = "p_state=texas&p_city=houston";
const sticky_proxy = "proxy_resi_ses_id=scrape_session_404&proxy_resi_ses_time=60";
const browserUrl = `wss://${username}:${password}@${endpoint}?${geolocation}&${sticky_proxy}`;

(async () => {
    const browser = await chromium.connectOverCDP(browserUrl);
    const page = await browser.newPage();
    await page.goto("https://ip.oxylabs.io/location");
    console.log(await page.title());
    await browser.close();
})();
```

{% endtab %}

{% tab title="JavaScript (Puppeteer)" %}

```javascript
import puppeteer from 'puppeteer';

(async () => {
    const username = 'USERNAME';
    const password = 'PASSWORD';
    const endpoint = 'hb.oxylabs.io';
    
    // Target Texas state and pin the residential IP for 60 minutes
    const geolocation = "p_state=texas&p_city=houston";
    const sticky_proxy = "proxy_resi_ses_id=scrape_session_404&proxy_resi_ses_time=60";
    const browserUrl = `wss://${username}:${password}@${endpoint}?${geolocation}&${sticky_proxy}`;

    const browser = await puppeteer.connect({
        browserWSEndpoint: browserUrl
    });
    const page = await browser.newPage();
    await page.goto('https://ip.oxylabs.io/location');
    await browser.close();
})();
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/es/agent-browser/geolocation-and-proxy-selection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
