zoukankan      html  css  js  c++  java
  • AttributeError: module 'websocket' has no attribute 'create_connection' websocket 爬虫

    抓取某个网站的数据,代码如下

      

    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

    如果觉得对您有帮助,麻烦您点一下推荐,谢谢!



    好记忆不如烂笔头
  • 相关阅读:
    hdu 1251(字典树)
    hdu 1556(树状数组)
    hdu 3275(线段树的延迟标记,我被坑了)
    TCL之容器
    Codeforces Round #587 (Div. 3) D. Swords
    struts2中多个文件同时上传
    ffmpeg的使用
    struts2中类型转换器
    struts中访问servlet API的方法
    struts2中多个逻辑action(方法)的动态调用
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/14913429.html
Copyright © 2011-2022 走看看