-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflinders.py
34 lines (32 loc) · 1.25 KB
/
flinders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import scraperwiki
from bs4 import BeautifulSoup
from datetime import datetime
import logging
def councildas():
applications_url = 'https://www.flinders.tas.gov.au/current-advertising'
html = scraperwiki.scrape(applications_url)
date_scraped = datetime.now().isoformat()
page = BeautifulSoup(html, 'html.parser')
das = page.find('div', id='docList')('h2')
records = []
for da in das:
council_reference, address, dummy = da.find_previous('h1').text.split('-')
description = da.text
info_url = 'https://www.flinders.tas.gov.au/' + da.find_all_next('li')[1].find('a')['href']
record = {
'council_reference': council_reference.strip(),
'address': address.strip() + ', Tasmania, Australia',
'description': description,
'info_url': info_url,
'date_scraped': date_scraped,
}
records = records + [record]
return records
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
os.environ["SCRAPERWIKI_DATABASE_NAME"] = "sqlite:///data.sqlite"
records = councildas()
for record in records:
logging.debug(record)
scraperwiki.sqlite.save(unique_keys=['council_reference'], data=record, table_name='data')