我正在尝试解析从国会图书馆下载的MARC文件。我已经使用PyZ3950成功下载了记录,但是当我尝试使用PyMarc解析文件时,我收到以下错误:
Traceback (most recent call last):
File "test.py", line 13, in <module>
for record in reader:
File "build/bdist.macosx-10.9-intel/egg/pymarc/reader.py", line 83, in next
ValueError: invalid literal for int() with base 10: '<PyZ3'
这是我的完整代码:
from PyZ3950 import zoom, zmarc
from pymarc import MARCReader
conn = zoom.Connection('z3950.loc.gov', 7090)
conn.databaseName = 'VOYAGER'
conn.preferredRecordSyntax = 'USMARC'
query = zoom.Query('CCL', 'ti="1066 and all that"')
res = conn.search(query)
reader = MARCReader(str(res))
for record in reader:
print record.title()
conn.close()
答案 0 :(得分:1)
您的陈述:
res = conn.search(query)
返回ResultSet
,相应地返回http://www.panix.com/~asl2/software/PyZ3950/zoom.html
r
中的每条记录resultSet
都包含r.data
因此,您必须为每个r.data
提供MARCReader,或者将它们全部连接起来。
这将有效:
from PyZ3950 import zoom, zmarc
from pymarc import MARCReader
conn = zoom.Connection('z3950.loc.gov', 7090)
conn.databaseName = 'VOYAGER'
conn.preferredRecordSyntax = 'USMARC'
query = zoom.Query('CCL', 'ti="1066 and all that"')
res = conn.search(query)
marc = ''
for r in res:
marc = marc + r.data
reader = MARCReader(marc)
for record in reader:
print record.title()
conn.close()