V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Deteriorator
V2EX  ›  Python

如何使用 Python 读取本地 IndexedDB 数据?

  •  
  •   Deteriorator · 2022-01-12 16:20:42 +08:00 · 2734 次点击
    这是一个创建于 806 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题

    我电脑上有个软件存储数据用的是 IndexedDB , 文件名后缀是 .ldb (LevelDB), 主要是我想把我以前记录的数据全部拿出来, 方便总结。 软件自身没有我想要总结功能

    但是我用 Python3.7+ 和 leveldb 库读取 *.leveldb 目录的时候一直报错

    >>> import leveldb
    >>> db = leveldb.LevelDB('****.leveldb')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    leveldb.LevelDBError: Invalid argument: idb_cmp1 does not match existing comparator : leveldb.BytewiseComparator
    

    用 plyvel 库也是同样的错误

    >>> import plyvel
    >>> db = plyvel.DB('****.leveldb')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "plyvel/_plyvel.pyx", line 247, in plyvel._plyvel.DB.__init__
      File "plyvel/_plyvel.pyx", line 94, in plyvel._plyvel.raise_for_status
    plyvel._plyvel.Error: b'Invalid argument: idb_cmp1 does not match existing comparator : leveldb.BytewiseComparator'
    

    有没有大佬知道怎么解决?

    4 条回复    2022-01-12 17:41:18 +08:00
    alphanow
        1
    alphanow  
       2022-01-12 16:59:38 +08:00   ❤️ 1
    你这个软件不是 Chrome 本身就是一个基于 Chromium 或者 Electron 开发的软件,因为 idb_cmp1 是 Chrome 用的 comparator 。你需要自己实现一个 comparator 。

    ```
    plyvel.DB(name, comparator=func, comparator_name="idb_cmp1")
    ```
    Deteriorator
        2
    Deteriorator  
    OP
       2022-01-12 17:07:44 +08:00
    @alphanow 有没有 comparator 实现的例子? 不明白这是啥
    alphanow
        3
    alphanow  
       2022-01-12 17:27:31 +08:00
    理论上你要实现和 Chromium 源代码一致的 comparator ,但如果是只读取数据的话,随便什么比较函数都行:
    def func(a,b):
    return 1 if a > b else ( -1 if a < b else 0)
    Deteriorator
        4
    Deteriorator  
    OP
       2022-01-12 17:41:18 +08:00
    @alphanow 多谢,我试试
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5458 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:43 · PVG 15:43 · LAX 00:43 · JFK 03:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.