正在读取原始(二进制?)使用Python从oninscan获取的Tiedot(NOSQL/JSON)数据

2024-09-29 23:15:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近一直在尝试使用Python包装器构建洋葱刮刀的tutorial。自从编写本教程以来,Onionscan已经从将所有数据存储在JSON文件中转变为将其中一些数据存储在使用Tiedot构建的数据库中。在

我试图找到一种方法来获取一个没有扩展名的文件,简单地命名为dat_0,并使用Python解析它。在

在macOS Textedit中查看dat_0,我得到以下信息。。。 dat_0 as displayed by Textedit

而崇高的文本显示为。。。 dat_0 as displayed in Sublime text

我一直在尝试如何使用Python解析这个文件。我从Tiedot的文档和Textedit的视图推测它使用JSON结构,但我运气不太好。在

import json
f = open('crawls/dat_0','rb')
data = json.dumps(f.read())

IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

或者

^{pr2}$

有人。。。 a) 知道这个文件是什么吗? b) 知道如何成功地解析它使数据在Python中可用吗?在


Tags: 文件theto数据jsondataratetutorial
1条回答
网友
1楼 · 发布于 2024-09-29 23:15:31

对于将来发现这种情况的人,我自己找到了解决办法。我使用Kaitai Struct为Tiedot文件结构创建一个二进制解析器。Kaitai可以为多种语言创建解析器,因此它是一个非常有用的工具

我用来生成解析器的Kaitai结构是。。。在

meta:
  id: parser
seq:
  - id: records
    type: record
    repeat: eos
types:
  record:
    seq:
    - id: validity
      type: s1
    - id: allocated
      type: s8le
    - id: document
      type: str
      encoding: utf-8
      terminator: 1
      eos-error: false

相关问题 更多 >

    热门问题