I. Open API Local Service Development Guide
1.1 API Usage
- Install and log in to the DICloak browser.
- Open More – Open API – Get Local Interface URL and Key.
- Obtain sample code and run the script.
1.2 Overview of Interface Usage
- When the interface request method is POST, the parameter passing method is via the body, passing JSON format data, not form-data, and not URL parameters.
- The interface returns a JSON object; if
code
is 0, it indicates success. If there is return data, it will be included in thedata
object. - If
code
is not 0, it indicates failure, and the failure message will be attached to themsg
field.
{
'code': 0,
'msg': 'success',
'data': {
'serial_number': 2,
'pid': '27028',
'debug_port': 17539
}
}
{
'code': 500,
'msg': 'fetch fail'
}
- All requests must include the request header:
X-API-KEY
, with the value being the key copied from the DICloak Software.
1.3 Example Code
The Dicloak browser uses the Chrome 120 kernel, so you need to download ChromeDriver first.
import time
import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# port and api key
BASE_URL = "http://127.0.0.1:52140/openapi"
API_KEY = "IvGM26nKG6XoSAtgJ84TAi9jrrwPqY8aWhwyDlY-4opXsqwex-OhLyFYv1e47rR2"
def open_browser(port):
"""
hold profile
:param port:
:return:
"""
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('debuggerAddress', f"127.0.0.1:{port}")
s = Service(r"G:\chromedriver.exe")
browser = webdriver.Chrome(options=chrome_options, service=s)
browser.get("https://www.zhihu.com")
def get_evn_list():
headers = {
"X-API-KEY": API_KEY,
}
params = {
"page_no": 1,
"page_size": 20
}
response = requests.get(f"{BASE_URL}/v1/env/list", params=params, headers=headers)
return response.json()
def open_env(env_id):
"""
open profile
:param env_id: id
:return:
"""
headers = {
"X-API-KEY": API_KEY,
}
response = requests.patch(f"{BASE_URL}/v1/env/{env_id}/open", headers=headers)
return response.json()
def close_env(env_id):
"""
close profile
:param env_id:
:return:
"""
headers = {
"X-API-KEY": API_KEY,
}
response = requests.patch(f"{BASE_URL}/v1/env/{env_id}/close", headers=headers)
return response.json()
if __name__ == '__main__':
resp = get_evn_list()
if resp['code'] != 0:
print(resp.msg)
exit(0)
# profile list
list = resp['data']['list']
if len(list) == 0:
print('no profile')
exit(0)
print(f"open profile:{list[0]['id']}")
open_resp = open_env(list[0]['id'])
if open_resp['code'] != 0:
print(open_resp['msg'])
exit(0)
print(f"open_resp : {open_resp}")
# Automatic
open_browser(open_resp['data']['debug_port'])
time.sleep(3)
# close profile
close_env(list[0]['id'])
II. Browser Profile Interface Details
GET Retrieve Browser Profile List
GET /v1/env/{env_id}/open
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
page_no | integer | Yes | Page number, default is 1 |
page_size | integer | Yes | Page size, default is 10 |
serial_num | integer | No | Serial number |
name | string | No | Name |
group_id | string | No | Group ID |
proxy_host | string | No | Proxy host (Method 1) |
status | string | No | Status (DISABLED: Disabled, ENABLED: Normal) |
platform_user | string | No | Platform |
remark | string | No | Remarks |
start_create_time | string | No | Start time |
end_create_time | string | No | End time |
operate_status | string | No | Browser profile open status (ENABLED: Open, DISABLED: Closed) |
X-API-KEY | request header | Yes |
Response Parameters
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | Browser Profile ID, env_id |
create_time | string | No | Creation time |
update_time | string | No | Modification time |
serial_num | integer | Yes | Serial number |
group_id | string | No | Group ID |
group_name | string | No | Group name |
name | string | Yes | Name |
browser | string | No | Browser type (CHROME: Chrome) |
ua_type | string | No | UA type |
ua | string | No | User Agent |
ua_os | string | No | User Agent OS |
cookie | string | No | Cookie |
other_cookie | string | No | Other cookie |
proxy_way | string | No | Proxy method (CUSTOM: Custom, SELECT_EXIST: Select Existing) |
proxy_id | string | No | Proxy ID (Method 2) |
proxy_type | string | No | Proxy type (Method 1) (NON_USE: Not used, HTTP, HTTPS, SSH, SOCKS5, IPFLY) |
proxy_host | string | No | Proxy host (Method 1) |
proxy_port | integer (int32) | No | Proxy port (Method 1) |
proxy_user_name | string | No | Proxy account (Method 1) |
proxy_passwd | string | No | Proxy password (Method 1) |
proxy_ip_type | string | No | IP query source (Method 1) (IP2LOCATION) |
urls | [string] | No | URL list |
config | string | No | Advanced settings JSON |
status | string | No | Status (DISABLED: Disabled, ENABLED: Normal) |
remark | string | No | Remarks |
last_open_time | string | No | Last opened time |
operate_status | string | No | Operation status (DISABLED: Closed, ENABLED: Enabled, LOCK: Locked) |
account_list | [object] | No | Account |
font_id | string | No | Font ID |
data_config | string | No | Data configuration |
browser_config | string | No | Browser configuration |
env_mutil_open_type | string | No | Browser profile multi-opening: GLOBAL: Global, ALLOW: Allow, BAN: Ban |
operate_members | [object] | No | Current browser profile operator information |
config_ext_map | object | No | Extended fields |
total | integer (int32) | Yes | Total count |
Response Example
{
"code": 0,
"msg": "success",
"data": {
"list": [
{
"id": "1848687666096832515",
"create_time": "2024-10-22 19:27:41",
"update_time": "2024-10-23 21:28:15",
"serial_num": 166,
"group_id": "1776895967565094913",
"group_name": null,
"name": "导入-账户-copy166-20241022192741216",
"browser": "CHROME",
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6005.0 Safari/537.36",
"ua_os": "MAC",
"cookie": "",
"other_cookie": null,
"urls": [],
"status": "ENABLED",
"remark": null,
"last_open_time": "2024-10-23 21:26:15",
"operate_status": "DISABLED",
"account_list": null,
"font_id": "",
"data_config": "{\"type\":25,\"dataType\":\"custom\"}",
"browser_config": "{\"type\":1,\"browserType\":\"custom\"}",
"env_mutil_open_type": "GLOBAL",
"config_ext_map": null
}
],
"total": 65
}
}
PATCH Open Browser Profile
PATCH /v1/env/{env_id}/open
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
env_id | string | Yes | Browser profile ID, corresponding to the id in the list. |
Response Parameters
Name | Type | Required | Description |
---|---|---|---|
serial_number | integer (int32) | Yes | Browser profile serial number |
pid | string | Yes | Browser profile process ID |
debug_port | integer | Yes | Browser profile port |
Response Example
{
'code': 0,
'msg': 'success',
'data': {
'serial_number': 2,
'pid': '27028',
'debug_port': 17539
}
}
PATCH Close Browser Profile
PATCH /v1/env/{env_id}/close
Request Parameters
Name | Type | Required | Description |
---|---|---|---|
env_id | string | Yes | Browser profile ID, corresponding to the id in the list. |
Response Parameters
Name | Type | Required | Description |
---|---|---|---|
serial_number | integer (int32) | Yes | Browser profile serial number |
pid | string | Yes | Browser profile process ID |
debug_port | integer | Yes | Browser profile port |
Response Example
{
'code': 0,
'msg': 'success'
}