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

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



    好记忆不如烂笔头
  • 相关阅读:
    app ios info权限配置:
    ionic3 小记录
    mipush ionic3 线上push
    ionic3 生命周期 之 ionViewWillLeave 坑
    iphone X 底部留白 之 ionic3 项目
    微信小程序 修改手机状态栏颜色
    git 命令
    微信小程序 下拉加载
    js 判断浏览器型号
    关于 ionic3 tabs 导航ico 点击 页面返回顶部
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/14913429.html
Copyright © 2011-2022 走看看