-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
63 lines (46 loc) · 1.83 KB
/
quickstart.py
File metadata and controls
63 lines (46 loc) · 1.83 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""BotCloud Quick Start - Playwright (Python)
This shows how to connect to BotCloud using Playwright's async API.
Prerequisites:
pip install playwright
playwright install chromium
Usage:
1. Modify the CONFIG section below with your token and proxy
2. Run: python examples/quickstart/playwright-python.py
"""
# ============ Configuration (Modify these) ============
CONFIG = {
"token": "your-token-here",
"proxy": "username:password@proxy.example.com:4600",
"device_type": "mac" # or "win", "android"
}
# ======================================================
import asyncio
import urllib.parse
from playwright.async_api import async_playwright
def build_endpoint() -> str:
"""Build BotCloud WebSocket endpoint URL."""
if not CONFIG["token"] or not CONFIG["proxy"]:
raise RuntimeError("Please configure token and proxy in CONFIG section above")
params = urllib.parse.urlencode({
"token": CONFIG["token"],
"--proxy-server": CONFIG["proxy"],
"device_type": CONFIG["device_type"],
})
return f"wss://cloud.bots.win?{params}"
async def main() -> None:
"""Main execution function."""
print("Connecting to BotCloud...")
async with async_playwright() as playwright:
browser = await playwright.chromium.connect_over_cdp(build_endpoint())
print("Connected! Getting context...")
context = browser.contexts[0] if browser.contexts else await browser.new_context()
page = await context.new_page()
print("Navigating to example.com...")
await page.goto("https://example.com")
print("Taking screenshot...")
await page.screenshot(path="screenshot.png")
print("Closing browser...")
await browser.close()
print("✅ Done! Check screenshot.png")
if __name__ == "__main__":
asyncio.run(main())