forked from exageraldo/raspagem-ordens-camara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raspagem.py
61 lines (54 loc) · 1.38 KB
/
raspagem.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
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
60
61
import sys
import os
import requests
from bs4 import BeautifulSoup
MONTHS = {
'01': 'Janeiro',
'02': 'Fevereiro',
'03': 'Marco',
'04': 'Abril',
'05': 'Maio',
'06': 'Junho',
'07': 'Julho',
'08': 'Agosto',
'09': 'Setembro',
'10': 'Outubro',
'11': 'Novembro',
'12': 'Dezembro'
}
YEARS_ID = {
'2019': '8',
'2018': '7',
'2017': '6',
'2016': '6',
'2015': '5'
}
for month in MONTHS:
print('{}...'.format(MONTHS[month]))
data = {
'ano_id': YEARS_ID['2018'],
'mes_id': month
}
url = "https://www.cmnat.rn.gov.br/ordens/send"
response = requests.post(url, data=data)
doc = BeautifulSoup(response.text, 'html.parser')
content = doc.select(".listagem-noticias li p a")
if not content:
continue
documents = [c.get_text() for c in content]
urls = [c['href'] for c in content]
path = 'documents/{}/'.format(MONTHS[month])
if not os.path.exists(path):
os.makedirs(path)
for doc, url in zip(documents, urls):
pdf = requests.get(url)
file_name = '{}'.format(
doc
.lstrip()
.lower()
.replace(' ', '_')
.replace('/', '_')
.replace('-', '_')
)
open('documents/{}/{}.pdf'.format(MONTHS[month],
file_name), 'wb').write(pdf.content)