Skip to content

Instantly share code, notes, and snippets.

@hhkaos
Last active September 12, 2022 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhkaos/341cfd4c8101afb5d56e35eda561e24e to your computer and use it in GitHub Desktop.
Save hhkaos/341cfd4c8101afb5d56e35eda561e24e to your computer and use it in GitHub Desktop.
Comisarias españa (fuente: policia.es)

Recuperado de https://www.policia.es/_es/dependencias_localizador_accesible_provincias.php# con el siguiente código:

let comisarias = {
  "type": "FeatureCollection",
  "features":[]
};

document.querySelectorAll(".list-group-flush .list-group-item").forEach(el =>{
    [lat,lon] = el.querySelector(".col-12 a").href.split("?q=")[1].split(",");
    comisarias.features.push({
      "type": "Feature",
      "properties": {
        nombre: el.querySelector(".display-4").innerText,
        direccion: el.querySelector(".row > dd").innerText
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          parseFloat(lon.replace(/%20/g, '')),
          parseFloat(lat.replace(/%20/g, '')),
        ]
      }
    })
});
copy(comisarias)
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment