Programmatic access to On-Line Encyclopedia of Integer Sequences

你。 提交于 2019-12-31 09:15:33

问题


Is there a way to search and retrieve the results from On-Line Encyclopedia of Integer Sequences (http://oeis.org) programmatically?

I have searched their site and the results are always returned in html. They do not seem to provide an API but in the policy statement they say its acceptable to access the database programmatically. But how to do it without screen scraping?

Thanks a lot for your help.


回答1:


The OEIS now provides several points of access, not just ones using their internal format. These seem largely undocumented, so here are all of the endpoints that I have found:


https://oeis.org/search?fmt=json&q=<sequenceTerm>&start=<itemToStartAt>

Returns a JSON formatted response of the results found from the sequenceTerm given. If too many results were returned, count will be > 0 whilst results will be null. If no results were returned, count will be 0. itemToStartAt is used for pagination of results, as only a maximum of 10 are ever returned. This starts at 0. If you wanted to return a second page of results, this would equal 10. Information about what each of the entries means can be found here.


https://oeis.org/search?fmt=text&q=<sequenceTerm>&start=<itemToStartAt>

Exactly the same arguments as before, however this returns it in the OEIS internal format. Which is largely written about here. Unless your project requires it, I'd highly recommend using the JSON format over this.


https://oeis.org/search?fmt=<json|text>&q=id:A<sequenceNumber>

Will return a single result if the sequenceNumber is found. This is the suggested method for obtaining single sequences, as it appears to be far more optimised than some of the alternative methods that can be used as queries. Requests often take under a second. Alternative search query methods can be found on this page.


https://oeis.org/A<sequenceNumber>/graph?png=1

This endpoint can be used to grab the images used to graph the data points. Alternatively, setting png to equal to zero returns the HTML page containing a graph of it.


https://oeis.org/recent.txt

This returns a list of recently updated entries in the OEIS internal format. There are no parameters available, or JSON format, as this seems like a static text file that is simply being served to the client. Due to the length of replies from the OEIS database (for some sequences replies can take above five seconds), I'd highly recommend heavily caching requests and using the above endpoint to update them when they change.




回答2:


A URL of the form http://oeis.org/search?fmt=text&q=2,5,14,50,233 gives a nicely formatted text output.

But it seems there is no way to get a single sequence in text form.




回答3:


If you happen to use Mathematica, it sounds like the following notebook might help. It allows you to specify a sequence and automatically import a detailed list of matching entries from the OEIS:

http://www.brotherstechnology.com/math/oeis_mathematica.html




回答4:


It looks like direct use of their CGI program is the only API they provide.

URL for Searching the Database




回答5:


https://oeis.org/search?q=id:A000032&fmt=text

gives the plain text form of an entry in their internal format

https://oeis.org/eishelp1.html



来源:https://stackoverflow.com/questions/5991756/programmatic-access-to-on-line-encyclopedia-of-integer-sequences

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!