# 地理位置定向

你可以通过添加以下内容为你的无头浏览器会话指定一个位置 `p_cc`, `p_city`，或 `p_state` 参数到您的连接 URL：

* `p_cc` – 选择国家，使用 2 位国家代码（例如，US、DE、FR）。如果未指定国家，系统将根据可用性自动分配一个国家。
* `p_city` – 选择以小写写法表示的城市（例如，berlin、los\_angeles 等）。你还必须指定以下之一 `p_cc` 或 `p_state`
* `p_state` – 选择一个州（仅适用于美国），当其以小写名称使用时（例如，texas、ohio）

以下是国家定位的代码示例：

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

```python
from playwright.sync_api import sync_playwright

username = "your-username"
password = "your-password"
endpoint = "ubc.oxylabs.io"
cc = "US"  # 将其替换为所需的 2 位国家代码
browser_url = f"wss://{username}:{password}@{endpoint}?p_cc={cc}"

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(browser_url)
    page = browser.new_page()
    page.goto('https://example.com')
    browser.close()
```

{% endtab %}

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

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

(async () => {
    const username = 'your-username';
    const password = 'your-password';
    const endpoint = 'ubc.oxylabs.io';
    const cc = 'US';  // 将其替换为所需的 2 位国家代码
    const browserUrl = `wss://${username}:${password}@${endpoint}?p_cc=${country}`;

    const browser = await chromium.connectOverCDP(browserUrl);
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await browser.close();
})();
```

{% endtab %}

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

```javascript
import puppeteer from 'puppeteer';

(async () => {
    const username = 'your-username';
    const password = 'your-password';
    const endpoint = 'ubc.oxylabs.io';
    const cc = 'US';  // 将其替换为所需的 2 位国家代码
    const browserUrl = `wss://${username}:${password}@${endpoint}?p_cc=${country}`;

    const browser = await puppeteer.connect({
        browserWSEndpoint: browserUrl
    });
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await browser.close();
})();
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**注意：** 如果 `p_state` 和 `p_cc` 都已指定， `p_state` 将优先使用并且 `p_cc` 将被忽略。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.oxylabs.io/products/cn/headless-browser/features/geolocation-targeting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
