Skip to content

Instantly share code, notes, and snippets.

@tom-henderson
Last active January 19, 2018 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom-henderson/670884eb2753563d60b64204f5ecc315 to your computer and use it in GitHub Desktop.
Save tom-henderson/670884eb2753563d60b64204f5ecc315 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup as bs
locations = ['Devonport', 'Takapuna']
data = {}
for location in locations:
url = "https://www.tenancy.govt.nz/rent-bond-and-bills/market-rent/?location={}".format(location)
html = requests.get(url).text
soup = bs(html, "html.parser")
l = {}
l['location'] = location
l['date'] = soup.find("span", class_="search_details").text
l['bonds'], l['lower'], l['mid'], l['upper'] = (i.text for i in soup.findAll("table", class_="css-table-tuck")[2].find("tbody").find("tr").findAll("td")[1:])
data[location] = l
for location in locations:
print data[location]['location'].ljust(9), data[location]['bonds'], data[location]['lower'], data[location]['mid'], data[location]['upper'], "({})".format(data[location]['date'])
rent = (float(data['Devonport']['lower'][1:]) + float(data['Devonport']['lower'][1:])) / 2
print "Target rent: ${0:.2f}".format(rent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment