{ "metadata": { "name": "", "signature": "sha256:49e11c757391da4ad4c602003e902c82acd9962dbf07198f7daa774f4962dd8a" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Accessing Remote Resources\n", "==========================\n", "\n", "Web pages and data\n", "------------------\n", "\n", "I have mentioned before how one can access data files on your hard drive, but Python also allows you to access remote data, for example on the internet. The easiest way to do this is to use the [requests](https://pypi.python.org/pypi/requests) module. To start off, you just can get the URL:" ] }, { "cell_type": "code", "collapsed": true, "input": [ "import requests\n", "\n", "response = requests.get('http://xkcd.com/353/')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "``response`` holds the response now. You can access the content as text via the text-property:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "response." ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": true, "input": [ "print(response.text[:1000]) # only print the first 1000 characters" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "\n", "\n", "\n", "xkcd: Python\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "