推荐学习书目
› 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 · Jan 12, 2022 · 4678 views
    This topic created in 1728 days ago, the information mentioned may be changed or developed.

    如题

    我电脑上有个软件存储数据用的是 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 replies  •  2022-01-12 17:41:18 +08:00
    alphanow
        1
    alphanow  
       Jan 12, 2022   ❤️ 1
    你这个软件不是 Chrome 本身就是一个基于 Chromium 或者 Electron 开发的软件,因为 idb_cmp1 是 Chrome 用的 comparator 。你需要自己实现一个 comparator 。

    ```
    plyvel.DB(name, comparator=func, comparator_name="idb_cmp1")
    ```
    Deteriorator
        2
    Deteriorator  
    OP
       Jan 12, 2022
    @alphanow 有没有 comparator 实现的例子? 不明白这是啥
    alphanow
        3
    alphanow  
       Jan 12, 2022
    理论上你要实现和 Chromium 源代码一致的 comparator ,但如果是只读取数据的话,随便什么比较函数都行:
    def func(a,b):
    return 1 if a > b else ( -1 if a < b else 0)
    Deteriorator
        4
    Deteriorator  
    OP
       Jan 12, 2022
    @alphanow 多谢,我试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   811 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:33 · PVG 06:33 · LAX 15:33 · JFK 18:33
    ♥ Do have faith in what you're doing.