Last active
January 19, 2018 03:03
-
-
Save tom-henderson/670884eb2753563d60b64204f5ecc315 to your computer and use it in GitHub Desktop.
This file contains 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
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