抓取某个网站的数据,代码如下
instrument_name = "BTC-25JUN21-28000-P" msg = { "jsonrpc": "2.0", "id": 3983, "method": "public/get_last_trades_by_instrument_and_time", "params": { "instrument_name": instrument_name, "start_timestamp": 1622822400000, "end_timestamp": 1623427200000, "count": 1000 } } headers = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1' } url = 'wss://test.deribit.com/ws/api/v2' ws = websocket.create_connection(url=url, headers=headers, timeout=15) ws.send(json.dumps(msg)) print(ws.recv())
报错如下
C:Python37python3.exe D:/spider_telegram/spider_17_deribit/spider_2_get_content.py Traceback (most recent call last): File "D:/spider_telegram/spider_17_deribit/spider_2_get_content.py", line 35, in <module> spider() File "D:/spider_telegram/spider_17_deribit/spider_2_get_content.py", line 28, in spider ws = websocket.create_connection(url=url, headers=headers, timeout=15) AttributeError: module 'websocket' has no attribute 'create_connection'
解决办法:
pip3 install websocket-client