I am trying to scrape latest bid and ask prices from this website "http://btc-exchange.com/" I can see that the prices are being provided by this socket.io
wss://pusher.mistertango.com/socket.io/?EIO=3&transport=websocket&sid=XXX
The sessionID is being generated from this call
https://pusher.mistertango.com/socket.io/?EIO=3&transport=polling&t=1517079662330-10
This is the code which I am currently using
import requests
from websocket import create_connection
import json
SID_url = "https://pusher.mistertango.com/socket.io/?EIO=3&transport=polling"
SID_req = requests.get(SID_url, headers={'User-Agent': 'Mozilla/5.0'}).text
SID = SID_req[SID_req.index("sid")+6:SID_req.index(",")-1]
print(SID_req)
print(SID)
ws = create_connection("wss://pusher.mistertango.com/socket.io/?EIO=3&transport=websocket&sid="+SID)
ws.send('2probe')
print(ws.recv())
ws.send('5')
print(ws.recv())
ws.send('42["subscribe",{"chan":"market-e559906eda4362f58bcaab40a4bfb5b4"}]')
while True:
result = ws.recv()
print(result)
ws.close()
This is the output of the code
ÿ0{"sid":"mURV8OnaNqax_AmvAAF2","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
mURV8OnaNqax_AmvAAF2
3probe
40
The messages which I have sent are based on the messages I saw in chrome-dev tool. Websocket msgs
My connection stops receiving any message after '40'. What am I doing wrong?