-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_ads.py
More file actions
42 lines (34 loc) · 1.56 KB
/
check_ads.py
File metadata and controls
42 lines (34 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests
# ================= 配置区 =================
# 1. 替换为你从 AdsPower 列表页看到的 ID
ADS_ID = "k18tsgsv"
# 2. 替换为你从设置中生成的 API Key
API_KEY = "3b1e025788842561bf3f903c847ad34d"
# 3. 默认端口通常是 50325
API_BASE = "http://local.adspower.net:50325"
# ==========================================
def test_handshake():
# 构造启动浏览器的 API URL
open_url = f"{API_BASE}/api/v1/browser/start?user_id={ADS_ID}"
# 根据 2026 最新安全规范,需要在 Header 中添加 Bearer Token
headers = {
'Authorization': f'Bearer {API_KEY}'
}
print(f"正在尝试唤起 AdsPower 窗口 (ID: {ADS_ID})...")
try:
response = requests.get(open_url, headers=headers).json()
if response.get("code") == 0:
ws_endpoint = response["data"]["ws"]["puppeteer"]
print("------------------------------------------")
print("✅ 握手成功!")
print(f"🔗 远程调试地址 (WS): {ws_endpoint}")
print("现在你可以让 Cursor 编写采集逻辑了。")
print("------------------------------------------")
else:
print(f"❌ 握手失败: {response.get('msg')}")
print("提示:请检查 AdsPower 客户端是否已登录并开启了 API 服务。")
except Exception as e:
print(f"⚠️ 连接出错: {e}")
print("请确保 AdsPower 已打开,且设置中的本地 API 端口为 50325。")
if __name__ == "__main__":
test_handshake()