Created
October 23, 2016 17:26
Star
You must be signed in to star a gist
Esempio per il Linux Day 2016 di Partanna
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
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "markdown", | |
"source": "# Intro\nQuello di sotto è un esempio su come usare `bash`, e alcune utility, per per convertire in formato formato `JSON` e `CSV` una tabella presente in una pagina HTML.\n\nRequisiti:\n- [scrape](https://github.com/jeroenjanssens/data-science-at-the-command-line/blob/master/tools/scrape);\n- [xml2json](https://github.com/Inist-CNRS/node-xml2json-command);\n- [csvkit](https://csvkit.readthedocs.io/en/0.9.1/)." | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "# Download\ncurl -s \"http://moduliweb.enac.gov.it/applicazioni/SAPR/APR_ReportOperatori.asp\" > \"01_file.html\"\n\n# Estrazione dati\n\n## XML\ncat 01_file.html | scrape -be 'table > form:not(:last-child)' > \"02_file.xml\"\n\n## JSON\n< \"02_file.xml\" xml2json > \"03_file.json\"\n\n# Strutturazione dei dati\n\n<\"03_file.json\" jq '[.html.body.form[] | {rifEnac:.tr.td[0].font.\"$t\",dataInformativa:.tr.td[1].font.\"$t\",riferimentoDichiarazione:.tr.td[2].font.\"$t\",DataDichiarazione:.tr.td[3].font.\"$t\",dataDichirazione:.td[3].font[\"#text\"],costruttore: .tr.td[5].font.\"$t\",tipo:.tr.td[6].font.\"$t\",mtom:.tr.td[7].font.\"$t\",apr:.tr.td[8].font.\"$t\",spr:.tr.td[9].font.\"$t\",flightController:.tr.td[10].font.\"$t\",scadenzaInoltro:.tr.td[11].font.\"$t\",nome:.tr.td[4].font.\"$t\"[0],indirizzo:.tr.td[4].font.\"$t\"[1],email:.tr.td[4].font.\"$t\"[2],pec:.tr.td[4].font.\"$t\"[3],telefono:.tr.td[4].font.\"$t\"[4]}]' > \"04_file_clean.json\"\n\n# conversione in CSV\n<\"04_file_clean.json\" in2csv -f json > \"05_file.csv\"", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "", | |
"name": "stdout" | |
} | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "bash", | |
"display_name": "Bash", | |
"language": "bash" | |
}, | |
"language_info": { | |
"mimetype": "text/x-sh", | |
"file_extension": ".sh", | |
"name": "bash", | |
"codemirror_mode": "shell" | |
}, | |
"anaconda-cloud": {}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "Esempio per il Linux Day 2016 di Partanna", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment