Skip to content

Instantly share code, notes, and snippets.

@famasya
Last active November 23, 2017 09:04
Show Gist options
  • Save famasya/f13896e7113ab82a0d60b9dbb9330a1a to your computer and use it in GitHub Desktop.
Save famasya/f13896e7113ab82a0d60b9dbb9330a1a to your computer and use it in GitHub Desktop.
import websocket, requests
def main():
url = "http://localhost:9222/json"
# Get DebuggerURL
connection = requests.get(url)
# Initiate websocket connection via debugger URL
ws = websocket.create_connection(connection.json()[0]['webSocketDebuggerUrl'])
ws.send(
json.dumps({
"id":0,
"method": "Runtime.evaluate",
"params": {
"expression": "location.href"
}
})
)
result = json.loads(ws.recv()).get("result")
print(result)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment