大致阅读了一下arxiv提供的文档,里面4.1. Simple Examples部分提供了4种语言的API请求样例。我的需求是使用Python,所以直接复制粘贴了。
网址:https://arxiv.org/help/api/user-manual
import urllib
url = 'http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=1'
data = urllib.urlopen(url).read()
print data
注意其中上面的代码执行可能会报错,因为会提醒我urllib没有urlopen这个方法,所以需要改2个地方;
import urllib.request
urllib.request.urlopen(url).read()
这个请求的格式可以看文档中4.2表格中paging example,下面的代码是我抄完后,按自己的需求改动,但arxiv中对于作者所属地信息的提供很大概率是缺失的。
"""
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.request
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'