Created
July 11, 2013 19:05
-
-
Save ZedThree/5978272 to your computer and use it in GitHub Desktop.
Zoopla houses thing as an ipython notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "zoopla_houses_notebook" | |
}, | |
"name": "zoopla_houses_notebook", | |
"nbformat": 2, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import re\nimport urllib2\nimport numpy as np\nfrom BeautifulSoup import BeautifulSoup\n \nhouse_webpage = 'http://www.zoopla.co.uk/for-sale/details/28121543'\n \n# Grab the whole webpage for the house listing\nsoup = BeautifulSoup(urllib2.urlopen(house_webpage).read())\n \n# Pull out the \"Property Description\" bit\ndesc = soup.find(\"div\",{\"class\":\"top\"}).text\n \n# Find the room sizes and put them in an array\nrooms = re.findall('\\d\\.\\d\\dm[ ]x[ ]\\d.\\d\\dm',desc)\n \n# Multiply the dimensions to get the area of each room\narea = []\nfor room in rooms:\n area.append( float(room.split()[0][:-1]) * float(room.split()[-1][:-1]) )\n \n# Now add up all the room areas\ntotal_area = np.array(area).sum()\n \n# Print the total area to screen\nprint total_area", | |
"language": "python", | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "42.5798" | |
} | |
], | |
"prompt_number": 1 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment