### Paging Through Search Results Source: https://info.arxiv.org/help/api/user-manual.html Example URLs demonstrating how to use start and max_results parameters to retrieve sequential chunks of data. ```text http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=10 (1) http://export.arxiv.org/api/query?search_query=all:electron&start=10&max_results=10 (2) http://export.arxiv.org/api/query?search_query=all:electron&start=20&max_results=10 (3) ``` -------------------------------- ### Query arXiv API with Perl Source: https://info.arxiv.org/help/api/basics.html Uses the LWP library to fetch and print the API response. LWP is typically available in standard Perl installations. ```perl use LWP; use strict; my $url = 'http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=1'; my $browser = LWP::UserAgent->new(); my $response = $browser->get($url); print $response->content(); ``` -------------------------------- ### Python arXiv API Query and Parsing Source: https://info.arxiv.org/help/api/examples/python_arXiv_parsing_example.txt This script performs a basic arXiv API call to search for 'electron' and parses the XML response using feedparser. It requires the `urllib` and `feedparser` libraries. Ensure `feedparser` is installed (`pip install feedparser`). ```python """ python_arXiv_parsing_example.py This sample script illustrates a basic arXiv api call followed by parsing of the results using the feedparser python module. Please see the documentation at http://export.arxiv.org/api_help/docs/user-manual.html for more information, or email the arXiv api mailing list at arxiv-api@googlegroups.com. urllib is included in the standard python library. feedparser can be downloaded from http://feedparser.org/ . Author: Julius B. Lucks This is free software. Feel free to do what you want with it, but please play nice with the arXiv API! """ import urllib import feedparser # Base api query url base_url = 'http://export.arxiv.org/api/query?'; # Search parameters search_query = 'all:electron' # search for electron in all fields start = 0 # retreive the first 5 results max_results = 5 query = 'search_query=%s&start=%i&max_results=%i' % (search_query, start, max_results) # Opensearch metadata such as totalResults, startIndex, # and itemsPerPage live in the opensearch namespase. # Some entry metadata lives in the arXiv namespace. # This is a hack to expose both of these namespaces in # feedparser v4.1 feedparser._FeedParserMixin.namespaces['http://a9.com/-/spec/opensearch/1.1/'] = 'opensearch' feedparser._FeedParserMixin.namespaces['http://arxiv.org/schemas/atom'] = 'arxiv' # perform a GET request using the base_url and query response = urllib.urlopen(base_url+query).read() # parse the response using feedparser feed = feedparser.parse(response) # print out feed information print 'Feed title: %s' % feed.feed.title print 'Feed last updated: %s' % feed.feed.updated # print opensearch metadata print 'totalResults for this query: %s' % feed.feed.opensearch_totalresults print 'itemsPerPage for this query: %s' % feed.feed.opensearch_itemsperpage print 'startIndex for this query: %s' % feed.feed.opensearch_startindex # Run through each entry, and print out information for entry in feed.entries: print 'e-print metadata' print 'arxiv-id: %s' % entry.id.split('/abs/')[-1] print 'Published: %s' % entry.published print 'Title: %s' % entry.title # feedparser v4.1 only grabs the first author author_string = entry.author # grab the affiliation in if present # - this will only grab the first affiliation encountered # (the first affiliation for the first author) # Please email the list with a way to get all of this information! try: author_string += ' (%s)' % entry.arxiv_affiliation except AttributeError: pass print 'Last Author: %s' % author_string # feedparser v5.0.1 correctly handles multiple authors, print them all try: print 'Authors: %s' % ', '.join(author.name for author in entry.authors) except AttributeError: pass # get the links to the abs page and pdf for this e-print for link in entry.links: if link.rel == 'alternate': print 'abs page link: %s' % link.href elif link.title == 'pdf': print 'pdf link: %s' % link.href # The journal reference, comments and primary_category sections live under # the arxiv namespace try: journal_ref = entry.arxiv_journal_ref except AttributeError: journal_ref = 'No journal ref found' print 'Journal reference: %s' % journal_ref try: comment = entry.arxiv_comment except AttributeError: comment = 'No comment found' print 'Comments: %s' % comment # Since the element has no data, only # attributes, feedparser does not store anything inside # entry.arxiv_primary_category # This is a dirty hack to get the primary_category, just take the # first element in entry.tags. If anyone knows a better way to do # this, please email the list! print 'Primary Category: %s' % entry.tags[0]['term'] # Lets get all the categories all_categories = [t['term'] for t in entry.tags] print 'All Categories: %s' % (', ').join(all_categories) # The abstract is in the element print 'Abstract: %s' % entry.summary ``` -------------------------------- ### Query arXiv API with Ruby Source: https://info.arxiv.org/help/api/basics.html Uses the standard net/http and uri modules to perform a GET request and print the response body. ```ruby require 'net/http' require 'uri' url = URI.parse('http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=1') res = Net::HTTP.get_response(url) print res.body ``` -------------------------------- ### Journal Reference Element Source: https://info.arxiv.org/help/api/user-manual.html Example of the journal reference element. ```xml Eur.Phys.J. C31 (2003) 17-29 ``` -------------------------------- ### Sorting API Search Results Source: https://info.arxiv.org/help/api/user-manual.html Example of a query URL utilizing sortBy and sortOrder parameters to organize returned articles. ```text http://export.arxiv.org/api/query?search_query=ti:"electron thermal conductivity"&sortBy=lastUpdatedDate&sortOrder=ascending ``` -------------------------------- ### DOI Element Source: https://info.arxiv.org/help/api/user-manual.html Example of the DOI element for an article. ```xml 10.1529/biophysj.104.047340 ``` -------------------------------- ### GET /query Source: https://info.arxiv.org/help/api/user-manual.html The primary interface for searching arXiv e-prints. Users can specify search queries or provide a list of IDs to retrieve metadata. ```APIDOC ## GET /query ### Description Retrieves metadata for e-prints based on search criteria or specific identifiers. ### Method GET ### Endpoint http://export.arxiv.org/api/query ### Parameters #### Query Parameters - **search_query** (string) - Optional - The search query string using arXiv search syntax. - **id_list** (string) - Optional - A comma-separated list of arXiv IDs to retrieve. - **start** (integer) - Optional - The index of the first result to return (for paging). - **max_results** (integer) - Optional - The maximum number of results to return. - **sortBy** (string) - Optional - The sort order for the results (e.g., relevance, lastUpdatedDate, submittedDate). - **sortOrder** (string) - Optional - The direction of the sort (ascending or descending). ### Response #### Success Response (200) - **Content-Type** (application/atom+xml) - The response is returned as an Atom feed containing entry metadata. ``` -------------------------------- ### Author Comment Element Source: https://info.arxiv.org/help/api/user-manual.html Example of the author comment element containing article metadata. ```xml 23 pages, 8 figures and 4 tables ``` -------------------------------- ### Ruby arXiv API Paging Script Source: https://info.arxiv.org/help/api/examples/ruby_arXiv_paging_example.txt This script demonstrates how to paginate through arXiv API results. It includes a delay between API calls to comply with API usage policies. Ensure you have the `feedtools` gem installed. ```ruby require 'RubyGems' require 'feed_tools' require 'net/http' require 'uri' # Feedtools will automatically sort the entries by date # set :entry_sorting_property to nil to instead leave the # default entrty order FeedTools.configurations[:entry_sorting_property] = nil # Base api query url base_url = 'http://export.arxiv.org/api/query?' # Search parameters search_query = 'all:biophysics' # search for electron in all fields start = 0 # start at the first result total_results = 20 # want 20 total results results_per_iteration = 5 # 5 results at a time wait_time = 3 # number of seconds to wait beetween calls puts 'Searching arXiv for %s' % search_query i = start while (i < total_results) puts "Results #{i} - #{i+results_per_iteration}" # Construct the query with the search parameters query = "search_query=#{search_query}&start=#{i}&max_results=#{results_per_iteration}" # perform a GET request and parse the feed all in one go feed = FeedTools::Feed.open(base_url+query) # Run through each entry, and print out information for item in feed.items puts 'arxiv-id: %s' % item.id.split('/abs/')[-1] puts 'Title: %s' % item.title # FeedTools v0.2.26 only allows one author puts 'First Author: %s' % item.author.name end i += results_per_iteration # Remember to play nice and sleep a bit before you call # the api again! puts 'Sleeping for %i seconds' % wait_time sleep(wait_time) end ``` -------------------------------- ### GET http://arxiv.org/api/query Source: https://info.arxiv.org/help/api/user-manual.html Retrieves an Atom feed containing search results based on the provided query parameters. ```APIDOC ## GET http://arxiv.org/api/query ### Description Retrieves a list of articles from arXiv based on search criteria. The response is returned as an Atom 1.0 feed. ### Method GET ### Endpoint http://arxiv.org/api/query ### Parameters #### Query Parameters - **search_query** (string) - Optional - The search query string (e.g., all:electron). - **id_list** (string) - Optional - A comma-separated list of arXiv IDs to retrieve. - **start** (integer) - Optional - The index of the first result to return (for paging). - **max_results** (integer) - Optional - The maximum number of results to return. ### Response #### Success Response (200) - **feed** (XML) - The Atom feed containing metadata and entries. - **opensearch:totalResults** (integer) - Total number of results available for the query. - **opensearch:startIndex** (integer) - The starting index of the current result set. - **opensearch:itemsPerPage** (integer) - The number of items returned in this response. ``` -------------------------------- ### Retrieve OpenSearch Result Metadata Source: https://info.arxiv.org/help/api/user-manual.html Elements for tracking total results, start index, and items per page for pagination. ```xml 1000 ``` ```xml 0 1 ``` -------------------------------- ### GET /api/query Source: https://info.arxiv.org/help/api/user-manual.html Queries the arXiv database for articles based on search criteria or specific IDs. ```APIDOC ## GET /api/query ### Description Queries the arXiv database for articles. Supports searching via query strings, filtering by specific IDs, and paging through results. ### Method GET ### Endpoint http://export.arxiv.org/api/query ### Parameters #### Query Parameters - **search_query** (string) - Optional - A string representing the search query to find articles. - **id_list** (comma-delimited string) - Optional - A comma-delimited list of arXiv IDs. - **start** (int) - Optional - The 0-based index of the first result to return (default: 0). - **max_results** (int) - Optional - The number of results to return (default: 10, max: 30000). - **sortBy** (string) - Optional - Sort order criteria: "relevance", "lastUpdatedDate", or "submittedDate". - **sortOrder** (string) - Optional - Sort direction: "ascending" or "descending". ``` -------------------------------- ### Ruby arXiv API Call and Feed Parsing Source: https://info.arxiv.org/help/api/examples/ruby_arXiv_parsing_example.txt This snippet makes a GET request to the arXiv API with specified search parameters and parses the returned feed using the feedtools gem. It requires the feedtools, net/http, and uri gems. ```ruby require 'RubyGems' require 'feed_tools' require 'net/http' require 'uri' # Feedtools will automatically sort the entries by date # set :entry_sorting_property to nil to instead leave the # default entrty order FeedTools.configurations[:entry_sorting_property] = nil # Base api query url base_url = 'http://export.arxiv.org/api/query?' # Search parameters search_query = 'all:electron' # search for electron in all fields start = 0 # retreive the first 5 results max_results = 5 # Construct the query with the search parameters query = "search_query=#{search_query}&start=#{start}&max_results=#{max_results}" # perform a GET request and parse the feed all in one go feed = FeedTools::Feed.open(base_url+query) ``` -------------------------------- ### API Error Response Source: https://info.arxiv.org/help/api/user-manual.html Example of an Atom feed returned when an API request results in an error. ```xml ArXiv Query: search_query=&id_list=1234.12345 http://arxiv.org/api/kvuntZ8c9a4Eq5CF7KY03nMug+Q 2007-10-12T00:00:00-04:00 1 0 1 http://arxiv.org/api/errors#incorrect_id_format_for_1234.12345 Error incorrect id format for 1234.12345 2007-10-12T00:00:00-04:00 arXiv api core ``` -------------------------------- ### Primary Category Element Source: https://info.arxiv.org/help/api/user-manual.html Example of the primary classification element within an Atom feed. ```xml ``` -------------------------------- ### Displaying Feed and OpenSearch Metadata in Ruby Source: https://info.arxiv.org/help/api/examples/ruby_arXiv_parsing_example.txt This code displays the title and last updated date of the parsed arXiv feed, along with OpenSearch metadata like total results, start index, and items per page. Ensure the feed object is already populated. ```ruby puts 'Feed title: %s' % feed.title puts 'Feed last updated: %s' % feed.updated # opensearch metadata such as totalResults, startIndex, # and itemsPerPage live in the opensearch namespase puts 'totalResults for this query: %s' % feed.find_node('opensearch:totalResults').to_a[0] puts 'startIndex for this query: %s' % feed.find_node('opensearch:startIndex').to_a[0] puts 'itemsPerPage for this query: %s' % feed.find_node('opensearch:itemsPerPage').to_a[0] puts ``` -------------------------------- ### GET /api/query Source: https://info.arxiv.org/help/api/user-manual.html Retrieves arXiv metadata. The API returns Atom feeds, which may include custom arXiv namespace elements for primary categories, comments, affiliations, journal references, and DOIs. ```APIDOC ## GET /api/query ### Description Retrieves arXiv metadata based on search queries or ID lists. The response is an Atom feed containing standard elements and specific arXiv extension elements. ### Method GET ### Endpoint http://export.arxiv.org/api/query ### Query Parameters - **id_list** (string) - Optional - A comma-separated list of arXiv identifiers. - **search_query** (string) - Optional - A search query string. - **start** (integer) - Optional - The index of the first result to return. - **max_results** (integer) - Optional - The maximum number of results to return. ### Response #### Success Response (200) - **feed** (XML) - An Atom feed containing entries with arXiv metadata extensions such as ``, ``, ``, ``, and ``. #### Error Response - **feed** (XML) - An Atom feed containing a single entry with a `` describing the error and a `` to detailed documentation. ``` -------------------------------- ### Constructing the Base API URL Source: https://info.arxiv.org/help/api/user-manual.html The base structure for all arXiv API requests, requiring a method name and parameters. ```text http://export.arxiv.org/api/{method_name}?{parameters} ``` -------------------------------- ### PHP arXiv API Query and Parsing Source: https://info.arxiv.org/help/api/examples/php_arXiv_parsing_example.txt This script constructs a query for the arXiv API, fetches results using SimplePie, and parses feed and OpenSearch metadata. Ensure SimplePie is included and configured. ```php # php_arXiv_parsing_example.php # # This sample script illustrates a basic arXiv api call # followed by parsing of the results using the Simplepie # module. # # Please see the documentation at # http://export.arxiv.org/api_help/docs/user-manual.html # for more information, or email the arXiv api # mailing list at arxiv-api@googlegroups.com. # # Simplepie can be gotten from http://simplepie.org/ # # Author: Julius B. Lucks, Bill Flanagan # # This is free software. Feel free to do what you want # with it, but please play nice with the arXiv API! include_once('./SimplePie/simplepie.inc'); define ('EOL', "
\n"); # Base api query url $base_url = 'http://export.arxiv.org/api/query?'; # Search parameters $search_query = 'all:electron'; # search for electron in all fields $start = 0; # retreive the first 5 results $max_results = 5; # Construct the query with the search parameters $query = "search_query=".$search_query."&start=".$start."&max_results=".$max_results; # SimplePie will automatically sort the entries by date # unless we explicitly turn this off $feed = new SimplePie($base_url.$query); $feed->enable_order_by_date(false); $feed->init(); $feed->handle_content_type(); # Use these namespaces to retrieve tags $atom_ns = 'http://www.w3.org/2005/Atom'; $opensearch_ns = 'http://a9.com/-/spec/opensearch/1.1/'; $arxiv_ns = 'http://arxiv.org/schemas/atom'; # print out feed information print("Print out feed information".EOL); print("Feed title: ".$feed->get_title().EOL); $last_updated = $feed->get_feed_tags($atom_ns,'updated'); print("Last Updated: ".$last_updated[0]['data'].EOL.EOL); # opensearch metadata such as totalResults, startIndex, # and itemsPerPage live in the opensearch namespase print("Opensearch metadata such as totalResults, startIndex, and itemsPerPage live in the opensearch namespase".EOL); $totalResults = $feed->get_feed_tags($opensearch_ns,'totalResults'); print("totalResults for this query: ".$totalResults[0]['data'].EOL); $startIndex = $feed->get_feed_tags($opensearch_ns,'startIndex'); print("startIndex for these results: ".$startIndex[0]['data'].EOL); $itemsPerPage = $feed->get_feed_tags($opensearch_ns,'itemsPerPage'); print("itemsPerPage for these results: ".$itemsPerPage[0]['data'].EOL.EOL); # Run through each entry, and print out information ``` -------------------------------- ### Perl arXiv API Paging Script Source: https://info.arxiv.org/help/api/examples/perl_arXiv_paging_example.txt This script illustrates paging of arXiv API results. It includes a recommended 3-second delay between API calls. Requires LWP and XML::Atom modules. ```perl # perl_arXiv_paging_example.pl # # This sample script illustrates paging of arXiv api # results. In order to play nice with the api, we # recommend that you wait 3 seconds between api calls. # # Please see the documentation at # http://export.arxiv.org/api_help/docs/user-manual.html # for more information, or email the arXiv api # mailing list at arxiv-api@googlegroups.com. # # LWP, and XML::Atom can be gotten from cpan.org # # Author: Julius B. Lucks # # This is free software. Feel free to do what you want # with it, but please play nice with the arXiv API! use LWP; use XML::Atom::Feed; use strict; # Base api query url my $base_url = 'http://export.arxiv.org/api/query?'; # Search parameters my $search_query = 'all:biophysics'; # search for electron in all fields my $start = 0; # start at the first result my $total_results = 20; # want 20 total results my $results_per_iteration = 5; # 5 results at a time my $wait_time = 3; # number of seconds to wait beetween calls # set up an LWP browser my $browser = LWP::UserAgent->new(); print "Searching arXiv for $search_query\n"; # Loop through each page of results, printing out the # article id's, titles, and authors for (my $i = $start; $i <= $total_results; $i += $results_per_iteration) { print "Results $i - ",$i + $results_per_iteration,".\n"; # Construct the query with the search parameters my $query = "search_query=$search_query". "&start=$i". "&max_results=$results_per_iteration"; # perform a GET request using the $base_url and $query my $response = $browser->get($base_url.$query); # parse the response using XML::Atom. my $feed = XML::Atom::Feed->new(\"$response->content()\"); foreach my $entry ($feed->entries()) { # split the id line to get just the arxiv id my @temp = split('/abs/',$entry->id()); print "arxiv-id: ",$temp[-1],".\n"; print "Title: ",$entry->title(),".\n"; # gather a list of authors my @authors = map { $_->name() } $entry->author(); print "Authors: ", join(', ',@authors),".\n"; } # Remember to play nice and sleep a bit before you call # the api again! print "Sleeping for $wait_time seconds\n"; sleep($wait_time); } ``` -------------------------------- ### Perl Script for arXiv API Query and Parsing Source: https://info.arxiv.org/help/api/examples/perl_arXiv_parsing_example.txt This script demonstrates a basic arXiv API call and parses the results using the XML::Atom module. It requires LWP and XML::Atom modules, which can be obtained from cpan.org. Ensure you play nice with the arXiv API. ```perl use LWP; use XML::Atom::Feed; use strict; # Base api query url my $base_url = 'http://export.arxiv.org/api/query?'; # Search parameters my $search_query = 'all:electron'; # search for electron in all fields my $start = 0; # retreive the first 5 results my $max_results = 5; # Construct the query with the search parameters my $query = "search_query=$search_query&start=$start&max_results=$max_results"; # set up an LWP browser my $browser = LWP::UserAgent->new(); # perform a GET request using the $base_url and $query my $response = $browser->get($base_url.$query); # parse the response using XML::Atom. my $feed = XML::Atom::Feed->new(\"$response->content()\"); # print out feed information print "Feed title: ",$feed->title(),"\n"; print "Feed last updated: ",$feed->updated(),"\n"; # opensearch metadata such as totalResults, startIndex, # and itemsPerPage live in the opensearch namespase my $opensearch_ns = XML::Atom::Namespace->new(opensearch => 'http://a9.com/-/spec/opensearch/1.1/'); print "totalResults for this query: ",$feed->get($opensearch_ns,'totalResults'),"\n"; print "startIndex for these results: ",$feed->get($opensearch_ns,'startIndex'),"\n"; print "itemsPerPage for these results: ",$feed->get($opensearch_ns,'itemsPerPage'),"\n"; print "\n"; # Run through each entry, and print out information # some entry metadata lives in the arXiv namespace my $arxiv_ns = XML::Atom::Namespace->new(arxiv => 'http://arxiv.org/schemas/atom'); foreach my $entry ($feed->entries()) { print "e-print metadata\n"; # split the id line to get just the arxiv id my @temp = split('/abs/',$entry->id()); print "arxiv-id: ",$temp[-1],"\n"; print "Published: ",$entry->published(),"\n"; print "Title: ",$entry->title(),"\n"; # gather a list of authors and affiliations # affiliations are under the arxiv namespace if present print "Authors: \n"; foreach my $author ($entry->author()) { print " ",$author->name(); if (my @affil_list = $author->getlist($arxiv_ns,'affiliation')) { print " (",join(', ',@affil_list),")\n"; } else { print "\n"; } } # get the links to the abs page and pdf for this e-print my @links = $entry->link(); for my $link (@links) { if ($link->rel() eq 'alternate') { print "abs page link: ",$link->href(),"\n"; } elsif ($link->title() eq 'pdf') { print "pdf link: ",$link->href(),"\n"; } } # The journal reference, comments and primary_category sections live under # the arxiv namespace my $journal_ref = $entry->get($arxiv_ns,'journal_ref') || 'No journal ref found'; print "Journal Reference: $journal_ref\n"; my $comments = $entry->get($arxiv_ns,'comment') || 'No comments found'; print "Comments: $comments\n"; # Since the primary_category element has no value, only attributes, # we have to use get_object. XML::Atom is a little funny here because it # requires we put the namespace as a string instead of an # XML::Atom::Namespace object my $primary_category = $entry->get_object('http://arxiv.org/schemas/atom', 'primary_category', 'XML::Atom::Category'); print "Primary Category: ",$primary_category->term(),"\n"; # Lets get all the categories my @all_categories = (); for my $category ($entry->category()) { push @all_categories, $category->term(); } print "All Categories: ",join(', ',@all_categories),"\n"; # The abstract is in the element print "Abstract: ",$entry->summary(); print "\n"; } ``` -------------------------------- ### Author Affiliation Element Source: https://info.arxiv.org/help/api/user-manual.html Example of an affiliation subelement nested within an Atom author tag. ```xml G. G. Kacprzak NMSU ``` -------------------------------- ### Query arXiv API with PHP Source: https://info.arxiv.org/help/api/basics.html Uses the core file_get_contents function to retrieve data from the API endpoint. ```php ``` -------------------------------- ### PHP arXiv API Paging Script Source: https://info.arxiv.org/help/api/examples/php_arXiv_paging_example.txt This script demonstrates how to paginate through arXiv API results. It uses SimplePie to parse the Atom feed and includes a delay between API calls to be polite to the arXiv API. ```php \n"); # atom namespace definition $atom_ns = "http://www.w3.org/2005/Atom"; # Base api query url $base_url = 'http://export.arxiv.org/api/query?'; # Search parameters $search_query = 'all:biophysics'; # search for electron in all fields $start = 0; # start at the first result $total_results = 20; # want 20 total results $results_per_iteration = 5; # 5 results at a time $wait_time = 3; # number of seconds to wait beetween calls print("Searching arXiv for ".$search_query."".EOL.EOL); # Loop through each page of results, printing out the # article id's, titles, and authors for ($i = $start; $i <= $total_results; $i += $results_per_iteration) { $next = $i + $results_per_iteration; print("Results ".$i." - ".$next."".EOL); # Construct the query with the search parameters $query = "search_query=".$search_query. "&start=".$i. "&max_results=".$results_per_iteration; # perform a GET request using the $base_url and $query # parse the response using SimplePie. # SimplePie will automatically sort the entries by date # unless we explicitly turn this off $feed = new SimplePie($base_url.$query); $feed->enable_order_by_date(false); $feed->init(); $feed->handle_content_type(); foreach ($feed->get_items() as $entry) { # split the id line to get just the arxiv id $temp = split('/abs/',$entry->get_id()); print("arxiv-id: ".$temp[1].EOL); print("Title: ".$entry->get_title().EOL); $published = $entry->get_item_tags($atom_ns,'published'); print("Published: ".$published[0]['data'].EOL); # gather a list of authors $authors = array(); foreach ($entry->get_authors() as $author) { array_push($authors,$author->get_name()); } $author_string = join(', ',$authors); print("Authors: ".$author_string.EOL.EOL); } # Remember to play nice and sleep a bit before you call # the api again! print("Sleeping for ".$wait_time." seconds".EOL.EOL); sleep($wait_time); } ?> ``` -------------------------------- ### Query arXiv API with Python Source: https://info.arxiv.org/help/api/basics.html Uses the standard library urllib module to fetch and print the API response. ```python import urllib, urllib.request url = 'http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=1' data = urllib.request.urlopen(url) print(data.read().decode('utf-8')) ``` -------------------------------- ### Typical API Call Structure Source: https://info.arxiv.org/help/api/user-manual.html Represents the request and response flow for an arXiv API query. ```text Request from url: http://export.arxiv.org/api/query (1) with parameters: search_query=all:electron . . . API server processes the request and sends the response . . . Response received by client. (2) ``` -------------------------------- ### Paginate arXiv API Results in Python Source: https://info.arxiv.org/help/api/examples/python_arXiv_paging_example.txt Use this script to retrieve a set number of results from the arXiv API by making iterative calls. It includes a mandatory delay between requests to avoid overwhelming the API. Requires `urllib` (standard library) and `feedparser`. ```python """ python_arXiv_paging_example.py This sample script illustrates paging of arXiv api results. In order to play nice with the api, we recommend that you wait 3 seconds between api calls. Please see the documentation at http://export.arxiv.org/api_help/docs/user-manual.html for more information, or email the arXiv api mailing list at arxiv-api@googlegroups.com. urllib is included in the standard python library. feedparser can be downloaded from http://feedparser.org/ . Author: Julius B. Lucks This is free software. Feel free to do what you want with it, but please play nice with the arXiv API! """ import urllib import time import feedparser # Base api query url base_url = 'http://export.arxiv.org/api/query?'; # Search parameters search_query = 'all:biophysics' # search for electron in all fields start = 0 # start at the first result total_results = 20 # want 20 total results results_per_iteration = 5 # 5 results at a time wait_time = 3 # number of seconds to wait beetween calls print 'Searching arXiv for %s' % search_query for i in range(start,total_results,results_per_iteration): print "Results %i - %i" % (i,i+results_per_iteration) query = 'search_query=%s&start=%i&max_results=%i' % (search_query, i, results_per_iteration) # perform a GET request using the base_url and query response = urllib.urlopen(base_url+query).read() # parse the response using feedparser feed = feedparser.parse(response) # Run through each entry, and print out information for entry in feed.entries: print 'arxiv-id: %s' % entry.id.split('/abs/')[-1] print 'Title: %s' % entry.title # feedparser v4.1 only grabs the first author print 'First Author: %s' % entry.author # Remember to play nice and sleep a bit before you call # the api again! print 'Sleeping for %i seconds' % wait_time time.sleep(wait_time) ``` -------------------------------- ### Parse arXiv Feed Entries in PHP Source: https://info.arxiv.org/help/api/examples/php_arXiv_parsing_example.txt Iterates through each entry in an arXiv feed, extracting and printing various metadata. Requires the SimplePie library and assumes a feed object is available. ```php Run through each entry, and print out information some entry metadata lives in the arXiv namespace".EOL); $i = 1; foreach ($feed->get_items() as $entry) { print("Entry ".$i++."".EOL); print("e-print metadata".EOL); $temp = split('/abs/',$entry->get_id()); print("arxiv-id: ".$temp[1].EOL); print("Title: ".$entry->get_title().EOL); $published = $entry->get_item_tags($atom_ns,'published'); print("Published: ".$published[0]['data'].EOL); # gather a list of authors and affiliation # This is a little complicated due to the fact that the author # affiliations are in the arxiv namespace (if present) # Manually getting author information using get_item_tags $authors = array(); foreach ($entry->get_item_tags($atom_ns,'author') as $author) { $name = $author['child'][$atom_ns]['name'][0]['data']; $affils = array(); # If affiliations are present, grab them if ($author['child'][$arxiv_ns]['affiliation']) { foreach ($author['child'][$arxiv_ns]['affiliation'] as $affil) { array_push($affils,$affil['data']); } if ($affils) { $affil_string = join(', ',$affils); $name = $name." (".$affil_string.")"; } } array_push($authors,' '.$name.EOL); } $author_string = join('',$authors); print("Authors: ".EOL.$author_string.EOL); # get the links to the abs page and pdf for this e-print foreach ($entry->get_item_tags($atom_ns,'link') as $link) { if ($link['attribs']['']['rel'] == 'alternate') { print("abs page link: ".$link['attribs']['']['href'].EOL); } elseif ($link['attribs']['']['title'] == 'pdf') { print("pdf link: ".$link['attribs']['']['href'].EOL); } } # The journal reference, comments and primary_category sections live under # the arxiv namespace $journal_ref_raw = $entry->get_item_tags($arxiv_ns,'journal_ref'); if ($journal_ref_raw) { $journal_ref = $journal_ref_raw[0]['data']; } else { $journal_ref = 'No journal ref found'; } print("Journal Reference: ".$journal_ref.EOL); $comments_raw = $entry->get_item_tags($arxiv_ns,'comment'); if ($comments_raw) { $comments = $comments_raw[0]['data']; } else { $comments = 'No journal ref found'; } print("Comments: ".$comments.EOL); $primary_category_raw = $entry->get_item_tags($arxiv_ns, 'primary_category'); $primary_category = $primary_category_raw[0]['attribs']['']['term']; print("Primary Category: ".$primary_category.EOL); # Lets get all the categories $categories = array(); foreach ($entry->get_categories() as $category) { array_push($categories,$category->get_label()); } $categories_string = join(', ',$categories); print("All Categories: ".$categories_string.EOL); # The abstract is in the element print("Abstract: ".$entry->get_description().EOL.EOL); } ?> ``` -------------------------------- ### Define OpenSearch Namespace Source: https://info.arxiv.org/help/api/user-manual.html The URI for the OpenSearch extension elements used in the feed. ```text http://a9.com/-/spec/opensearch/1.1/ ``` -------------------------------- ### Retrieve Resource Links Source: https://info.arxiv.org/help/api/user-manual.html Link elements provide access to the abstract page, PDF, or DOI, distinguished by rel and title attributes. ```xml ```