# 参数说明

瞭解 Thordata 的 網頁解鎖器 - 抓取參數。

`Token`**(必填)：**\
該參數定義了爬取時使用的 API 令牌。對於您的成功爬取起到決定性作用。

| 參數    | 名稱    | 作用            |
| ----- | ----- | ------------- |
| token | Token | 爬取時驗證的 API 令牌 |

`URL`**(必填)：**\
該參數定義了爬取的目的網站連結，預設值為 google.com。您也可以更改為其他搜尋引擎連結。

| 參數  | 名稱  | 作用         |
| --- | --- | ---------- |
| url | URL | 爬取的目的網站的連結 |

**示例請求：**

帶有`token`:<mark style="color:blue;">Token ,</mark>`url`:<mark style="color:blue;"><https://www.google.com></mark> 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True"
```

<details>

<summary><code>js_render</code> <strong>，</strong>JS渲染<strong>(非必填)</strong></summary>

JS渲染能夠處理動態載入的內容和單頁應用(SPA)，支援更互動複雜的頁面和渲染需求，建議您開啟。

`js_render`=True

`js_render`=False

**示例請求：**

帶有 `js_render`:<mark style="color:blue;">True</mark> 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True"
```

</details>

<details>

<summary><code>type</code> <strong>，</strong>輸出格式<strong>(非必填)</strong></summary>

該參數定義了抓取結果的輸出格式。可選擇HTML和PNG格式，預設為HTML。

`format`=HTML

`format`=PNG

**示例請求：**

帶有 `type`:<mark style="color:blue;">png</mark> 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=png" -d "js_render=True"
```

</details>

<details>

<summary><code>header</code> <strong>，</strong>Header<strong>(非必填)</strong></summary>

啟用後，輸出結果中會包含請求頭的信息。

**示例請求：**

帶有 `header`:<mark style="color:blue;">Ture</mark> 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request \
 -H "Authorization: Bearer token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "url=https://www.google.com" \
 -d "type=html" \
 -d "js_render=True" \
 -d "header=True"
```

</details>

<details>

<summary><code>block_resources</code><strong>，</strong>阻止<strong>(非必填)</strong></summary>

該參數可限制不必要的資源抓取，從而加快抓取速度。

`block_resources`=圖片

`block_resources`=Javascript腳本

**示例請求：**

帶有 `block_resources`:<mark style="color:blue;">script</mark> 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True" -d "block_resources=script"
```

</details>

<details>

<summary><code>country</code><strong>，代理(非必填)</strong></summary>

該參數定義了爬取時的代理使用哪個國家/地區，預設值無代理國家。

`country`=隨機

`country`=任意國家代碼

**示例請求：**

帶有`country`:<mark style="color:blue;">al</mark> 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request -H "Authorization: Bearer Token" -H "Content-Type: application/x-www-form-urlencoded" -d "url=https://www.google.com" -d "type=html" -d "js_render=True" -d "country=al"
```

</details>

<details>

<summary><code>clean_content</code><strong>，清除(非必填)</strong></summary>

此參數用於從返回結果中刪除 `JS` 和 `CSS` 內容。

**示例请求：**

帶有 `clean_content: JS,CSS` 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request \
 -H "Authorization: Bearer token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "url=https://www.google.com" \
 -d "type=html" \
 -d "js_render=True" \
 -d "clean_content=js,css" \
 -d "header=False"
```

</details>

<details>

<summary><code>wait</code><strong>，等待（毫秒）(非必填)</strong></summary>

該參數旨在等待頁面加載內容所需的毫秒數。（適用於速度較慢的網站）

**示例请求：**

带有帶有 `wait:1000` 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request \
 -H "Authorization: Bearer token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "url=https://www.google.com" \
 -d "type=html" \
 -d "js_render=True" \
 -d "wait=10000"
```

</details>

<details>

<summary><code>wait_for</code><strong>，等待选择器(非必填)</strong></summary>

等待 CSS 選擇器在 DOM 中載入，若同時使用 `wait_for` 和 `wait`，則以 `wait_for` 為優先（覆蓋固定時間）。指定元素最長等待 30 秒，超時後會自動返回網站內容。

**示例请求：**

带有帶有 `wait_for:.content` 的參數示例

```sh
curl -X POST https://webunlocker.thordata.com/request \
 -H "Authorization: Bearer token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "url=https://www.google.com" \
 -d "type=html" \
 -d "js_render=True" \
 -d "wait=10000" \
 -d "wait_for=.content"
```

</details>

<details>

<summary><code>headers</code><strong>，自定義headers(非必填)</strong></summary>

傳遞自定義headers到您正在抓取的網站。（例如：{"name":"value"}）

**示例请求：**

如果您想發送 `User-Agent` 和 `Content-Type`，則應如下所示：

```sh
curl -X POST https://webunlocker.thordata.com/request \
 -H "Authorization: Bearer token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "url=https://www.google.com" \
 -d "type=html" \
 -d "js_render=token" \
 -d 'headers=[{"name":"name1","value":"value1"}]' \
 -d 'cookies=[{"name":"name2","value":"value2"}]'
```

</details>

<details>

<summary><code>cookies</code><strong>，</strong>Cookies<strong>(非必填)</strong></summary>

將自定義 cookie 傳遞給目標網站，多個 cookies 時請用英文分號 `;` 分隔。

Cookie 是網站透過瀏覽器存儲在用戶設備上的小塊數據。它們允許網站保留用戶資訊，例如登入狀態、偏好設定或追蹤詳情，從而改善並個人化瀏覽體驗。

發出請求時，您可以通過兩種方式添加 cookie：

1. **在 `headers` 參數中**：以以下格式將其作為 `Cookie` 標頭的一部分發送：

（例如：`headers:{"name":"Cookie","value":"cookie_name_1=cookie_value_1"}`)

1. **使用專用的 `cookies` 參數**：直接以以下格式傳遞：\
   （例如：{"`"Cookie`":"`cookie_name_1=cookie_value_1`"}）

**示例请求：**

使用專用的 `cookies` 參數：直接以以下格式傳遞：\
`cookie_name_1=cookie_value_1; cookie_name_2=cookie_value_2`

```sh
curl -X POST https://webunlocker.thordata.com/request \
 -H "Authorization: Bearer token" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -d "url=https://www.google.com" \
 -d "type=html" \
 -d "js_render=token" \
 -d 'headers=[{"name":"name1","value":"value1"}]' \
 -d 'cookies=[{"name":"name2","value":"value2"}]'
```

</details>
