Fork me on GitHub

Erin Hengel

Software > Requests-NBER

Requests-NBER is (yet another) custom Requests class, now for NBER.org, the website of the National Bureau of Economic Research. Like its predecessors, Requests-NBER includes methods to directly access bibliographic information and PDFs for papers released as NBER working papers.

Installation

Install Requests-NBER with pip:

$ pip install requests_nber

To install from source, download the latest version on GitHub.com and run the following command:

$ python setup.py install

I have only ever tested Requests-NBER on Python 3.4. If you are on a Mac, Python 2.7 is pre-installed by default; upgrade at python.org and follow the instructions in the Installation section of Textatistic to update the python command link (or just use python3, instead).

Log in

The NBER class logs onto NBER.org and establishes a connection with the host. The session attribute returns a Requests Session object with all the methods of the main Requests API. For example:

>>> import requests_nber
>>> deets = {'username': 'someuser', 'password': 'XXXX'}
>>> conn = requests_nber.NBER(login=deets)
>>> conn.url
'https://www.nber.org/'

Access NBER working papers

The NBER class contains the html, pdf and ref methods to download the webpage HTML, PDF and bibliographic information of articles released as NBER working papers, respectively. These methods are identical to the corresponding methods described in Requests-AEAweb. A brief description is provided here.

Download PDFs

To return the contents of a PDF in bytes, use the pdf method and indicate the document identifier using the id keyword argument. If you also supply file with a file name, the PDF is automatically saved for you; otherwise, you'll need to manually save a copy of it using Python's I/O functions.

>>> pdf = conn.pdf(id='t1', file='article.pdf')

Note that the actual NBER report ID number for ‘t1’ is ‘t0001’. NBER automatically redirects to the appropriate PDF file.

Download bibliographic data

The ref method returns a dictionary of bibliographic information on an article. As before, use the id keyword argument to fill in the relevant document identifier. In the following example, I use ref to get the authors and abstract of the paper "A Stochastic Approach to Disequilibrium Macroeconomics":

>>> biblio = conn.ref(id='t1')
>>> biblio['author']
'Seppo Honkapohja and Takatoshi Ito'

Many NBER working papers’ webpages cite where papers were eventually published. To retrieve this information, set the published keyword to true when calling ref. If the information is found, it is returned in the dictionary under the published keyword.

>>> biblio = conn.ref(id='t1', published=True)
>>> biblio['published']
'Published: Honkapohja, Seppo and Takatoshi Ito. "On Macroeconomic Equilibrium with Stochastic Rationing." Scandinavian Journal of Economics, Vol. 87, No. 1, 1985, pp. 66-88.'
Download HTML

html returns the raw HTML code from an article's webpage. Please see the documentation for Requests-AEAweb and Requests-Raven for several examples and more information on how to use this method.

License

Copyright 2016 Erin Hengel

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.