6

I'm trying to use the metadata harvesting package https://pypi.python.org/pypi/pyoai to harvest the data on this site https://www.duo.uio.no/oai/request?verb=Identify

I tried the example on the pyaoi site, but that did not work. When I test it I get a error. The code is:

from oaipmh.client import Client
from oaipmh.metadata import MetadataRegistry, oai_dc_reader

URL = 'http://uni.edu/ir/oaipmh'
registry = MetadataRegistry()
registry.registerReader('oai_dc', oai_dc_reader)
client = Client(URL, registry)

for record in client.listRecords(metadataPrefix='oai_dc'):
    print record

This is the stack trace:

Traceback (most recent call last):
  File "/Users/arashsaidi/PycharmProjects/get-new-DUO/get-files.py", line 8, in <module>
    for record in client.listRecords(metadataPrefix='oai_dc'):
  File "/Users/arashsaidi/.virtualenvs/lbk/lib/python2.7/site-packages/oaipmh/common.py", line 115, in method
    return obj(self, **kw)
  File "/Users/arashsaidi/.virtualenvs/lbk/lib/python2.7/site-packages/oaipmh/common.py", line 110, in __call__
    return bound_self.handleVerb(self._verb, kw)
  File "/Users/arashsaidi/.virtualenvs/lbk/lib/python2.7/site-packages/oaipmh/client.py", line 65, in handleVerb
    kw, self.makeRequestErrorHandling(verb=verb, **kw))    
  File "/Users/arashsaidi/.virtualenvs/lbk/lib/python2.7/site-packages/oaipmh/client.py", line 273, in makeRequestErrorHandling
    raise error.XMLSyntaxError(kw)
oaipmh.error.XMLSyntaxError: {'verb': 'ListRecords', 'metadataPrefix': 'oai_dc'}

I need to get access to all the files on the page I have linked to above plus generate an additional file with some metadata.

Any suggestions?

4

2 回答 2

3

我最终使用了 Sickle 包,我发现它有更好的文档并且更易于使用:

此代码获取所有集合,然后从每个集合中检索每个记录。考虑到要处理的记录超过 30000 条,这似乎是最好的解决方案。对每一组都这样做可以提供更多的控制权。希望这可以帮助其他人。我不知道图书馆为什么使用 OAI,对我来说似乎不是组织数据的好方法......

# gets sickle from OAI
        sickle = Sickle('http://www.duo.uio.no/oai/request')
        sets = sickle.ListSets()  # gets all sets
        for recs in sets:
            for rec in recs:
                if rec[0] == 'setSpec':
                    try:
                        print rec[1][0], self.spec_list[rec[1][0]]
                        records = sickle.ListRecords(metadataPrefix='xoai', set=rec[1][0], ignore_deleted=True)
                        self.write_file_and_metadata()
                    except Exception as e:
                        # simple exception handling if not possible to retrieve record
                        print('Exception: {}'.format(e))
于 2014-12-28T23:29:57.333 回答
1

来自 pyoai 站点 ( http://uni.edu/ir/oaipmh )的链接似乎已失效,因为它返回 404。
不过,您应该能够像这样从您的网站获取数据:

from oaipmh.client import Client
from oaipmh.metadata import MetadataRegistry, oai_dc_reader

URL = 'https://www.duo.uio.no/oai/request'
registry = MetadataRegistry()
registry.registerReader('oai_dc', oai_dc_reader)
client = Client(URL, registry)

# identify info
identify = client.identify()
print "Repository name: {0}".format(identify.repositoryName())
print "Base URL: {0}".format(identify.baseURL())
print "Protocol version: {0}".format(identify.protocolVersion())
print "Granularity: {0}".format(identify.granularity())
print "Compression: {0}".format(identify.compression())
print "Deleted record: {0}".format(identify.deletedRecord())

# list records
records = client.listRecords(metadataPrefix='oai_dc')
for record in records:
    # do something with the record
    pass

# list metadata formats
formats = client.listMetadataFormats()
for f in formats:
    # do something with f
    pass
于 2014-12-26T14:08:38.143 回答