Skip to content
Advertisement

how decode this message in websocket

mycode :

from selenium import webdriver
import sys
import  time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import os
import json

chrm_options=Options()
chrm_caps = webdriver.DesiredCapabilities.CHROME.copy()
chrm_caps['goog:loggingPrefs'] = { 'performance':'ALL' }
#driver = webdriver.Chrome(executable_path = 'chromedriver.exe', chrome_options=chrm_options,desired_capabilities=chrm_caps) Windows
driver = webdriver.Chrome(executable_path = 'C:chromedriver.exe', chrome_options=chrm_options,desired_capabilities=chrm_caps) #Linux


def LoadWebDriver() :
    print("Web driver Init ")
    base_url = "https://pocketoption.com/en/cabinet/demo-quick-high-low/#td"  #Change the site
    print('Loading URL ....')
    driver.get(base_url )
    

def WebSocketLog():
    for wsData in driver.get_log('performance'):
        #print(wsData) 
        wsJson = json.loads((wsData['message']))
        print(wsData)
#         if wsJson["message"]["method"]== "Network.webSocketFrameReceived":
#             print ("Rx :"+ str(wsJson["message"]["params"]["timestamp"]) + wsJson["message"]["params"]["response"]["payloadData"])
#         if wsJson["message"]["method"] =="Network.webSocketFrameSent":
#             print ("Tx :"+ wsJson["message"]["params"]["response"]["payloadData"])


LoadWebDriver()
print("Waiting")
time.sleep(30) #Capture messages for 30sec, integrate your code here

meessage recived :

Rx :451-["updateStream",{"_placeholder":true,"num":0}]
Rx :W1siQVVEQ0hGIiwxNjMzNTI1MDg2LjM2NiwwLjY3Mjc4XV0=
Rx :451-["updateStream",{"_placeholder":true,"num":0}]
Rx :W1siQVVEQ0hGIiwxNjMzNTI1MDg2LjU0NywwLjY3MjgxXV0=
Rx :451-["updateStream",{"_placeholder":true,"num":0}]
Rx :W1siQVVEQ0hGIiwxNjMzNTI1MDg2LjY5NywwLjY3Mjc5XV0=
Rx :451-["updateStream",{"_placeholder":true,"num":0}]
Rx :W1siQVVEQ0hGIiwxNjMzNTI1MDg3LjU2NiwwLjY3Mjc5XV0=

in puppter messages is god but in selenium show like this

Advertisement

Answer

Hi the Rx values look like base64 encoded string. After using the function below I get this values, is this what you are expecting ?

[[“AUDCHF”,1633525087.566,0.67279]]

import base64    
def base64ToString(b):
        return base64.b64decode(b).decode('utf-8')
        
b = "W1siQVVEQ0hGIiwxNjMzNTI1MDg3LjU2NiwwLjY3Mjc5XV0="
print(base64ToString(b))
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement