> For the complete documentation index, see [llms.txt](https://doc.thordata.com/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.thordata.com/doc/zh-hk/zhua-qu-liu-lan-qi/yan-zheng-ma-jie-jue-fang-an.md).

# 驗證碼解決方案

### **驗證碼解決方案**

\
在使用我們的採集瀏覽器時，難免會遇到需要解決的風險控制驗證碼。這些驗證碼可能會影響您的自動化任務。但請放心，我們將協助您解決這一問題。

### **自訂CDP功能**

\
若遇到風險控制驗證碼，您需要透過CDP命令通知我們。收到指令後，我們將協助完成驗證碼破解。您只需發送CDP命令：`Captchas.automaticSolver` 並附上需要破解的驗證碼類型即可。

### **自動驗證碼破解功能**

\
您只需在可能出現驗證碼的程式碼部分加入以下程式碼片段，透過CDP命令告知我們需要破解的驗證碼類型，我們將立即協助處理。

{% tabs %}
{% tab title="Puppeteer" %}

```sh
const page = await page.newPage();  
await page.goto('https://example.com');  
```

{% endtab %}

{% tab title="Selenium" %}

```python
res = driver.execute_cdp_cmd("Captchas.automaticSolver", {
        "timeout": 120000,   # Please allow sufficient time, and 2 minutes is recommended.
        "solverType": "cloudflare"
    })
    print(f"Captchas solver result: {res}")
```

{% endtab %}
{% endtabs %}

### **範例說明**

{% tabs %}
{% tab title="JavaScript" %}

```sh
const puppeteer = require('puppeteer-core');

const Target_URL = "https://example.com";

const wsUrl = 'wss://{AUTH}@ws-browser.thordata.com';  //Your credentials
async function run(){

  // connect browser
  const browser = await puppeteer.connect({
	  browserWSEndpoint: wsUrl,
  });
  try{
	  console.log("Connected to browser...");
	
	  // Create a new page
	  const page = await browser.newPage();

	  // Go to target site
	  await page.goto(Target_URL, { waitUntil: "networkidle0" });

	  // Obtain the CDP client and send a custom CDP protocol
	  const client = await page.createCDPSession();
	  try {
		  const res = await client.send('Captchas.automaticSolver',{
			"timeout": 120000,  // Please allow sufficient time, and 2 minutes is recommended.
			"solverType": "cloudflare"   // Use the corresponding type.
		  });
		  
		  // {message: 'Solver meaages', success: true, timestamp: 170000000}
		  console.log("res=", res) 
	  } catch(e) {
		  console.error("err=", e)
	  }
	
	  // Verification
	  await page.screenshot({ path: 'solver_cf.png'});  
	  const title = await page.title();
	  console.log("title=", title);

  } catch (error) {
	  console.error(error);
  }
  finally{
	  console.info("browser closed")
	  await browser.close();
  }
 
}
run();
```

{% endtab %}

{% tab title="Python" %}

```python
import time

from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
from selenium.webdriver import Remote, ChromeOptions

scbr_connection =ChromiumRemoteConnection("https://{AUTH}@hs-browser.thordata.com", 'goog', 'chrome')

with Remote(sbr_connection, options=ChromeOptions()) as driver:
    print('Connected!')

    driver.get('https://example.com')
	
    # Send a custom CDP
    res = driver.execute_cdp_cmd("Captchas.automaticSolver", {
        "timeout": 120000,
        "solverType": "datadome"
    })
    #  {message: 'Solver message', success: true, timestamp: 170000000}
    print(f"Captchas solver result: {res}")
    print("title", driver.title)  
	
    # screenshot
    print('Page screenshot')
    driver.get_screenshot_as_file('./solver_cf.png')
```

{% endtab %}
{% endtabs %}

### **參數規範**

\
發送CDP命令時，必須包含 `solverType` 參數。

```
cloudflare    
google-v2    
datadome
```

### &#x20;**統一返回結構**

\
無論您使用我們的驗證碼解決方案破解何種類型的驗證碼，其返回結構均保持一致。

```
res= {
  message: 'captcha solver success',   //Description
  success: true,  //Sovler status   
  timestamp: 1755763768   //Timestamp
}
```


---

# 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 dynamically by asking a question.

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

```
GET https://doc.thordata.com/doc/zh-hk/zhua-qu-liu-lan-qi/yan-zheng-ma-jie-jue-fang-an.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
