This article represents instructions on how to get started with programming casperjs scripts within 10 minutes. In this article, the sample program is written for scraping Amazon.com homepage and printing title of the page.
One of the biggest issues or hurdle, I would say, in getting started with any framework is related with downloading the tool/library, installing and configuring the environment in order to execute the program. Thanks to Docker creators, this is taken care in a very neat manner so much so that one could do following to set up the development environment in literally no time.
Docker Container for Casperjs
For those of you not aware of what are dockers, do check their website, http://www.docker.com. Also, check my previous article on setting up docker on your windows box. In order to get started with Casperjs, first step is to download the image of Casperjs container from following page.
https://github.com/philalex/docker-casperjs
Once the zip file gets downloaded, unzip the file, goto that folder and run following commands to create a container:
# Pull the docker image
docker pull philalex/docker-casperjs
# Command to run the container with image philalex/docker-casperjs
docker run -ti -dP --name casper1 philalex/docker-casperjs
Alternatively, you could just run the following command. It checks if an image is present and the runs the container using that image. In case the image is not present, it downloads the image first and then runs the container.
# Command to run the container with image philalex/docker-casperjs
docker run -ti -dP --name casper1 philalex/docker-casperjs
Once the container is created, execute the following command to start and attach the container:
# Start the container
docker start casper1
# Attach the container
docker attach casper1
Once the container gets started, do the following in the /home folder.
var casper = require('casper').create();
casper.start('http://www.amazon.com', function() {
this.echo(this.getTitle());
});
casper.run();
casperjs sample.js
In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…
Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…
With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…
Anxiety is a common mental health condition that affects millions of people around the world.…
In machine learning, confounder features or variables can significantly affect the accuracy and validity of…
Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…