Last active
July 12, 2021 17:35
-
-
Save bplmp/d66936b480fe13ed591bdd0257099d27 to your computer and use it in GitHub Desktop.
Extrair autos de infração do IBAMA de HTML para CSV
This file contains hidden or 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
| # baixe os dados | |
| curl http://dadosabertos.ibama.gov.br/dados/SIFISC/auto_infracao/auto_infracao/auto_infracao.html > autos.html | |
| # gere csv | |
| # (primeiro passo é quebrar as linhas, acelera o processamento) | |
| cat autos.html \ | |
| | sed -e 's|<\/tr>|\n|g' \ | |
| | sed -e 's/.*<thead\sbgcolor\=\"\#808080\">//' \ | |
| -e 's|\salign\=\"center\"||g' \ | |
| -e 's|<\/th>|\|\|\||g' \ | |
| -e 's|</thead><tbody>|\n|g' \ | |
| -e 's|<th>||g' \ | |
| -e 's|<\/td>|\|\|\||g' \ | |
| -e 's|<td>||g' \ | |
| -e 's|<tr>||g' \ | |
| -e 's|<\/tr>|\n|g' \ | |
| -e 's|</tbody></table></body></html>||g' \ | |
| > autos.csv | |
| # obs: os separadores são três pipes, ou ||| | |
| # é um separador esquisito mas precisava de uma sequência que não ocorria no arquivo | |
| # leia no python | |
| # (no openoffice ele se atrapalha com esse separador) | |
| import pandas as pd | |
| df = pd.read_csv('autos.csv', sep='\|\|\|') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CSV gerado, em arquivo zip: https://drive.google.com/file/d/1L--aN609E_XfsZ-Gm-ESVIL-OL6LbmiX/view?usp=sharing