Skip to content

Instantly share code, notes, and snippets.

@moeiscool
Created July 14, 2019 17:05
Show Gist options
  • Save moeiscool/c08ce68fccfd3a5fd3d8cac42a31bd9d to your computer and use it in GitHub Desktop.
Save moeiscool/c08ce68fccfd3a5fd3d8cac42a31bd9d to your computer and use it in GitHub Desktop.
Extract Frames from website as PNG images with PhantomJS
  1. run npm install phantomjs-prebuilt inside the directory where these files are located (launch.js and webpageRecord.js).
  2. run node launch.js
  3. See frames folder for images.
var fs = require('fs')
var path = require('path')
var childProcess = require('child_process')
var phantomjs = require('phantomjs-prebuilt')
var binPath = phantomjs.path
var childArgs = [path.join(__dirname, 'webpageRecord.js')]
var process = childProcess.spawn(binPath, childArgs)
var frame = 0
process.stdout.on('data',function(data){
console.log(data.toString())
})
// process.stderr.on('data',function(){
// console.log(data.toString())
// })
var page = require("webpage").create();
page.viewportSize = { width: 1920, height: 1080 };
page.open("https://www.accuweather.com/en/ca/vancouver/v6c/weather-forecast/53286", function() {
setTimeout(function() {
// Initial frame
var frame = 0;
// Add an interval every 25th second
setInterval(function() {
// Render an image with the frame name
page.render("frames/weather" + frame++ + ".png", { format: "png" })
// Exit after 50 images
if (frame > 100) {
phantom.exit();
}
}, 1000);
}, 666);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment