Created
February 4, 2019 04:12
-
-
Save parzibyte/b01b62ab32962a9edeb53d8fe9df84dd to your computer and use it in GitHub Desktop.
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
/** | |
* Ejemplificar uso de node-webshot con PhamtomJS | |
* para guardar una página web como una imagen | |
* | |
* @author parzibyte | |
*/ | |
// Requerir módulo | |
const webshot = require("node-webshot"); | |
// Algunas constantes explicativas | |
const SITIO_WEB = "https://www.facebook.com/", | |
NOMBRE_IMAGEN_SALIDA = "salida.png"; | |
// Opciones para tomar captura | |
const OPCIONES = { | |
customHeaders: { | |
'Accept-Language': 'es_LA', // Lenguaje de la página | |
}, | |
shotSize: { | |
width: 'all', | |
height: 'all' | |
}, | |
screenSize: { | |
width: 1024, // Anchura de pantalla | |
height: 760, // Altura de pantalla | |
}, | |
// Indicar que "somos" Chrome en Windows | |
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' | |
}; | |
// Función que se llama cuando la captura se ha tomado | |
const cuandoSeTomeCaptura = err => { | |
// Puede que haya un error | |
if (err) { | |
console.log("Lo siento, ocurrió un error: ", err); | |
} else { | |
console.log(`La página ${SITIO_WEB} ha sido guardada en ${NOMBRE_IMAGEN_SALIDA}`); | |
} | |
}; | |
// Ahora sí, tomar captura o screenshot | |
webshot(SITIO_WEB, NOMBRE_IMAGEN_SALIDA, OPCIONES, cuandoSeTomeCaptura); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment