Repository navigation
Expand file tree
/
Copy pathget_LA.py
More file actions
59 lines (52 loc) · 2.19 KB
/
Copy pathget_LA.py
File metadata and controls
59 lines (52 loc) · 2.19 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import configparser
from utils import Crawler as CoreCrawler
import re
class Crawler(CoreCrawler):
abbr = 'LA'
def _get_remote_filename(self, local_filename):
year = re.match('.*((?:19|20)\d{2}).pdf', local_filename).group(1)
if local_filename.startswith('City of '):
directory = 'General Purpose'
name = local_filename.replace('City of ', '')
else:
if 'Inc.' in local_filename or 'Foundation' in local_filename:
directory = 'Non-Profit'
else:
directory = 'Special District'
name = local_filename
filename = '{} {}'.format(self.abbr, name)
return directory, filename, year
if __name__ == '__main__':
config = configparser.ConfigParser()
config.read('conf.ini')
crawler = Crawler(config, 'loisiana')
crawler.get(config.get('loisiana', 'url').strip())
hrefs_clicked = []
for url in crawler.get_attr('#parishes a', 'href', single=False)[:-1]:
loaded = False
while not loaded:
crawler.get(url)
loaded = True
for box in crawler.get_elements('div.box'):
href = crawler.get_attr('a', 'href', root=box)
if href in hrefs_clicked:
continue
loaded = False
hrefs_clicked.append(href)
crawler.click('a', root=box)
crawler.wait_for_displayed('tr.even')
while True:
for row in crawler.get_elements('tbody tr'):
year = crawler.get_text('.sorting_1', root=row).split('/')[-1]
crawler.download(
crawler.get_attr('a', 'href', root=row),
'{} {}.pdf'.format(crawler.get_text('b', root=row), year)
)
crawler.upload_to_ftp('{} {}.pdf'.format(crawler.get_text('b', root=row), year))
try:
crawler.assert_exists('li.next.disabled')
break
except Exception:
crawler.click('li.next a')
break
crawler.close()