My main confusion was not realizing that The Open Archives Initiative Protocol for Metadata Harvesting is a separate protocol, not a subset of arXiv API.
In this case, the relevant queries are ListIdentifiers
(10k items per query) and ListRecords
(1k items per query). To get just identifiers we need to write:
http://export.arxiv.org/oai2?verb=ListIdentifiers&set=math&metadataPrefix=oai_dc
It results in 10k identifiers in the following form:
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2015-02-16T19:28:22Z</responseDate>
<request verb="ListIdentifiers" metadataPrefix="oai_dc" set="math">http://export.arxiv.org/oai2</request>
<ListIdentifiers>
<header>
<identifier>oai:arXiv.org:0704.0002</identifier>
<datestamp>2008-12-13</datestamp>
<setSpec>math</setSpec>
</header>
...
<header>
<identifier>oai:arXiv.org:0712.1769</identifier>
<datestamp>2011-06-23</datestamp>
<setSpec>math</setSpec>
</header>
<resumptionToken cursor="0" completeListSize="249546">760571|10001</resumptionToken>
</ListIdentifiers>
</OAI-PMH>
As there are more results, to get next batch we need to specify resumptionToken
, in this case:
http://export.arxiv.org/oai2?
verb=ListIdentifiers&resumptionToken=760571|10001
and so on.
Other useful parameters are from
and until
, e.g. as in
http://export.arxiv.org/oai2?verb=ListIdentifiers&set=math&metadataPrefix=oai_dc&from=2015-01-14&until=2015-01-14
To directly get categories (bear in mind that set=math
specifies mathematics, but there are no smaller subsets), one can write:
http://export.arxiv.org/oai2?verb=ListRecords&set=math&from=2015-01-01&until=2015-01-31&metadataPrefix=arXiv
It's important to set metadataPrefix=arXiv
, so that subdisciplines will be listed:
<categories>
math-ph cond-mat.other math.MP nlin.CD physics.class-ph
</categories>
EDIT:
I used delay as Nate Eldredge suggested, in my case - 25s. Yet, while trying to get all math (250k items so in 250 queries) it gave error at 70. I did continue it (with even higher delay) but sometime around 110 the query was not longer available.
So, the way to go is in getting smaller chunks - e.g. by month (or for mathematics - at most by year).
Net::OAI::Harvester
. The OAI API does provide a way to download all records (ListRecords
), rather than just one at a time (GetRecord
). It looks like arXiv will give you 1000 records and then return a 503 asking you to retry after a delay, so it's not to prevent excessive leeching as @Compass says but only to rate limit.Net::OAI::Harvester
knows to how to retry (listAllRecords
) but not how to delay, so that may need to be done manually.