gpt4 book ai didi

python-2.7 - 用python打开warc文件

转载 作者:行者123 更新时间:2023-12-04 19:05:34 25 4
gpt4 key购买 nike

我正在尝试使用以下链接中的工具箱使用 python 打开一个 warc 文件:
http://warc.readthedocs.org/en/latest/

打开文件时:

import warc
f = warc.open("00.warc.gz")

一切都很好, f 对象是:
<warc.warc.WARCFile instance at 0x1151d34d0>

但是,当我尝试使用以下方法读取文件中的所有内容时:
for record in f:
print record['WARC-Target-URI'], record['Content-Length']

出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/xxx/anaconda/lib/python2.7/site-packages/warc/warc.py", line 390, in __iter__
record = self.read_record()
File "/Users/xxx/anaconda/lib/python2.7/site-packages/warc/warc.py", line 373, in read_record
header = self.read_header(fileobj)
File "/Users/xxx/anaconda/lib/python2.7/site-packages/warc/warc.py", line 331, in read_header
raise IOError("Bad version line: %r" % version_line)
IOError: Bad version line: 'WARC/0.18\n'

这是因为我使用的 warc 工具箱或其他东西不支持我的 warc 文件版本吗?

最佳答案

ClueWeb09 数据集以 WARC 0.18 格式提供。但是,它有几个问题。有些记录是 malformed .

The most prevalent problem is an extra newline in the WARC header. There are a few cases of other malformed headers also.



此外,它不使用标准的\r\n 行尾标记,这实际上是您的问题。

warc-clueweb library可以处理。这是一个特殊的 python 库,用于处理 ClueWeb09 WARC 文件。根据文档

Only minor modifications to the original library were made. The original documentation of the warc library still holds

关于python-2.7 - 用python打开warc文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25784825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com