Created
October 24, 2019 01:08
Import pour scrapper parcs et jardins de Nantes
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
node_modules/ | |
package-lock.json |
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
const fs = require('fs'); | |
const puppeteer = require('puppeteer-core'); | |
(async () => { | |
const browser = await puppeteer.launch({ | |
executablePath: '/snap/bin/chromium'//'/usr/bin/google-chrome' | |
}); | |
const page = await browser.newPage(); | |
await page.goto('https://jardins.nantes.fr/N/Jardin/Parcs-Jardins/Carte/Carte-Jardin-Tous.asp', { | |
timeout: 3000000 | |
}); | |
// Récupération des parcs | |
const geojson = await page.evaluate(() => { | |
return window.locations.reduce(function(acc, curr) { | |
acc.features.push({ | |
"type": "Feature", | |
"properties": { | |
libellepoint: curr[0], | |
codepoint: curr[3], | |
surfacepoint: curr[4] | |
}, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
curr[2], | |
curr[1] | |
] | |
} | |
}) | |
return acc; | |
}, { | |
"type": "FeatureCollection", | |
"features": [] | |
}) | |
}); | |
console.log('Geojson:', geojson); | |
fs.writeFileSync('parcs-jardin-nantes.geojson', JSON.stringify(geojson, null, ' '), { | |
encoding: 'utf-8' | |
}); | |
await browser.close(); | |
})(); |
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
{ | |
"name": "scrapping-parcs-jardins-nantes", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"puppeteer-core": "^1.20.0" | |
} | |
} |
Loading
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