> 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.

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

## Parámetros de geolocalización

Puede 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 debe especificar ya sea <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" %}
El targeting a nivel de ciudad funciona como *preferencia de mejor esfuerzo*. Si el grupo de proxies residenciales no tiene un proxy disponible en la ubicación exacta solicitada, vuelve automáticamente al ámbito de 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>). Consulte la lista completa de <a href="https://content.gitbook.com/content/BQ7Zf9paoN3FTeGcyfY1/blobs/cVjpiu1GKicluiVIT9og/us_states.txt">estados admitidos</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` están ambos especificados, `p_state` tiene prioridad y `p_cc` se ignora.
{% endhint %}

## Selección de proxy (proxies persistentes)

Por defecto, la puerta de enlace del proxy asigna una IP de salida nueva a cada sesión única de conexión del navegador. Como alternativa, puede fijar una IP de salida residencial específica durante intentos continuos de conexión del navegador incluyendo el `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 del rastreador de sesión alfanumérico de 3 a 36 caracteres.</td><td>cadena</td></tr><tr><td><code>proxy_resi_ses_time</code></td><td>Número de minutos para mantener fija la IP de salida del proxy residencial. Mín. 1 minuto, máx. 1440 minutos (24 horas).</td><td>entero</td></tr></tbody></table>

```bash
# Ejemplo: fijar una IP con base en EE. UU. durante 60 minutos
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, debe pasar valores idénticos para ambos `proxy_resi_ses_id` y `proxy_resi_ses_time` en cada cadena de URL posterior.
{% endhint %}

## Ejemplos de código

Los siguientes ejemplos muestran cómo construir cadenas de conexión que aplican targeting geográfico junto con restricciones persistentes de IP de proxy residencial.

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

```python
from playwright.sync_api import sync_playwright

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

# Orientar a la ciudad de Nueva York y fijar la IP residencial durante 30 minutos
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";

// Orientar al estado de Texas y fijar la IP residencial durante 60 minutos
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';
    
    // Orientar al estado de Texas y fijar la IP residencial durante 60 minutos
    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.
