用python打开warc文件

use*_*348 5 python-2.7 warc

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

使用以下方式打开文件时:

import warc
f = warc.open("00.warc.gz")
Run Code Online (Sandbox Code Playgroud)

一切都很好,并且f对象是:

<warc.warc.WARCFile instance at 0x1151d34d0>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用以下方法读取文件中的所有内容时:

for record in f:
     print record['WARC-Target-URI'], record['Content-Length']
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

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'
Run Code Online (Sandbox Code Playgroud)

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

小智 5

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

最普遍的问题是WARC标头中有多余的换行符。还有一些其他格式错误的标头的情况。

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

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

仅对原始库进行了少量修改。warc库的原始文档仍然保留