我正在尝试使用 元数据 </跨度> 收获包https://pypi.python.org/pypi/pyoai收集本网站上的数据https://www.duo.uio.no/oai/request?verb=Identify
我在 makeRequestErrorHandling上尝试了这个例子 引发错误.XMLSyntaxError(kw)oaipmh.error.XMLSyntaxError:{‘verb’:‘ListRecords’,‘metadataPrefix’:‘oai_dc’}
我需要访问我上面链接的页面上的所有文件,并生成一些附加文件 元数据 </跨度> 。
有什么建议?
我最终使用了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))
似乎来自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