25 lines
473 B
Python
25 lines
473 B
Python
|
|
#!/usr/bin/env python3
|
||
|
|
import sys
|
||
|
|
import websocket
|
||
|
|
|
||
|
|
if len(sys.argv) < 2:
|
||
|
|
print("Usage: python wsclient.py ws://localhost:9222/devtools/page/XYZ")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
url = sys.argv[1]
|
||
|
|
ws = websocket.WebSocket()
|
||
|
|
ws.connect(url)
|
||
|
|
|
||
|
|
print(f"Connected to {url}")
|
||
|
|
try:
|
||
|
|
while True:
|
||
|
|
msg = input("> ")
|
||
|
|
if msg.lower() in {"exit", "quit"}:
|
||
|
|
break
|
||
|
|
ws.send(msg)
|
||
|
|
print(ws.recv())
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
pass
|
||
|
|
finally:
|
||
|
|
ws.close()
|