Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active September 12, 2021 21:46
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 ThomasG77/f123512d54fa23de8797a4c47c847f07 to your computer and use it in GitHub Desktop.
Save ThomasG77/f123512d54fa23de8797a4c47c847f07 to your computer and use it in GitHub Desktop.

Make screen from Geoportail site, hiding help

Node version

Prerequisites

Get Node.js with associated npm

Install

npm i

Run

# Default to file example.png
node screenshot-geoportail.js your_geoportail_url

or

node screenshot-geoportail.js your_geoportail_url filename.png

Real example in action

node screenshot-geoportail.js 'https://www.geoportail.gouv.fr/carte?c=-1.55364,47.218383000000046&z=11&l0=ORTHOIMAGERY.ORTHOPHOTOS::GEOPORTAIL:OGC:WMTS(1)&permalink=yes' out.png

Python version

Prerequisites

Get Python 3.6+ and associated pip

Install

python -m pip install pyppeteer

Run

# Default to file example.png
python screenshot-geoportail.py your_geoportail_url

or

python screenshot-geoportail.py your_geoportail_url filename.png

Real example in action

python screenshot-geoportail.py 'https://www.geoportail.gouv.fr/carte?c=-1.55364,47.218383000000046&z=11&l0=ORTHOIMAGERY.ORTHOPHOTOS::GEOPORTAIL:OGC:WMTS(1)&permalink=yes' out.png
{
"name": "tmp",
"version": "1.0.0",
"description": "",
"main": "screenshot-geoportail.js",
"dependencies": {
"puppeteer": "^10.2.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
/**
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const puppeteer = require('puppeteer');
var myArgs = process.argv.slice(2);
if (myArgs.length == 1 || myArgs.length == 2) {
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const my_url = myArgs[0]; //'https://www.geoportail.gouv.fr/carte?c=-1.55364,47.218383000000046&z=11&l0=ORTHOIMAGERY.ORTHOPHOTOS::GEOPORTAIL:OGC:WMTS(1)&permalink=yes';
await page.goto(my_url, {
waitUntil: 'networkidle0',
});
const helpLayer = '#help-layer';
await page.waitForSelector(helpLayer);
await page.click(helpLayer);
//await page.waitForNavigation({waitUntil: "domcontentloaded"})
let outputPath = 'example.png';
if (myArgs.length == 2) {
outputPath = myArgs[1];
}
await page.screenshot({ path: outputPath});
await browser.close();
})();
} else {
console.log('You must provide an URL in the arg');
};
import sys
import asyncio
from pyppeteer import launch
args = sys.argv[1:]
if len(args) == 1 or len(args) == 2:
async def main():
browser = await launch()
page = await browser.newPage()
my_url = args[0]
await page.goto(my_url, {
"waitUntil": 'networkidle0',
})
helpLayer = '#help-layer'
await page.waitForSelector(helpLayer)
await page.click(helpLayer)
outputPath = 'example.png'
if len(args) == 2:
outputPath = args[1]
await page.screenshot({"path": outputPath})
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
else:
print('You must provide an URL in the arg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment