Nightmare.js is a high-level browser automation library designed to automate browsing tasks for sites with no API. By leveraging Electron as a browser, Nightmare.js can be used to quickly and easily run automation scripts without the need for a graphical user interface. This guide provides instructions on how to install Nightmare.js on Ubuntu 16.04 and run automation scripts. Furthermore, with its high-level API and minimal setup, Nightmare.js is the perfect tool for quickly and easily automating web-browsing tasks.
Uncover the Essentials Before You Take the First Step: What You Need to Know Before You Begin!
- Start the Journey to a Successful Setup with our Getting Started Guide – Set Your Linode’s Hostname & Timezone Now!
- Secure Your Server Now: Follow This Guide to Create a Standard User Account, Harden SSH Access, and Remove Unnecessary Network Services.
- Keep Your System Up-to-Date – Get the Latest Updates Now!
sudo apt-get update && sudo apt-get upgrade
Unlock the Power of Node.js – Install Now for Unlimited Possibilities!
Although the Ubuntu 16.04 repository is significantly slower to release more recent versions of Node.js, users can still install the most up-to-date version available through the NodeSource PPA (formerly Chris Lea’s Launchpad PPA). Consequently, users can ensure they have access to the latest version of Node.js without having to wait for the Ubuntu repository to become updated.
- Unlock NodeSource’s Powerful Node.js Capabilities With One Easy PPA Installation!
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
- Get Started with Node.js and NPM in no Time – Easily Install with this One Simple Command!
sudo apt-get install -y nodejs
- Confirm Your Node.js Installation: Unlock the Power of JavaScript Today!
node --version
- Ensure Your NPM Command-line Tool is Installed Properly – Check Now!
npm --version
Elevate Your Web Development with Nightmare.js – Instantly Unlock Its Power and Efficiency!
To effectively avoid installing the Node packages globally, it is recommended to install Nightmare.js in a specific directory. For example, this approach creates an automation directory within the current user’s home directory as the base for the project. Consequently, this allows for the packages to remain isolated and organized, without cluttering the global node_modules directory.
- Automate Your Way to Success: Create and Switch to the Automation Directory!
mkdir ~/automation && cd ~/automation
- Get Your NPM Project Up and Running in No Time – Use the ‘-f Force’ Flag to Automatically Accept Default Values!
npm init
- Get Ready For Sweet Dreams with Nightmare.js – Easily Install It Today!
npm install --save nightmare
Unlock the Power of Automation with a Simple Script: Create and Run Your Own Automation Script!
Nightmare.js is an NPM module, so it can be easily imported from within a Node.js script. This module can be used to write a simple script that will search Linode’s documentation for guides about Ubuntu. To use the module, simply import it into the script and use it to search the documentation. This can be a great way to quickly and easily find the information needed to get started with Ubuntu.
- Go Beyond Your Nightmares: Install xvfb and Its Dependencies for Running Graphical Applications Without Display Hardware with Nightmare.js and Electron!
sudo apt-get install -y xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps clang libdbus-1-dev libgtk2.0-dev libnotify-dev libgnome-keyring-dev libgconf2-dev libasound2-dev libcap-dev libcups2-dev libxtst-dev libxss1 libnss3-dev gcc-multilib g++-multilib
- Automate Your Development Process with Easy Creation of Node.js in Automation Directory!
File: ~/automation/linode.js
const Nightmare = require('nightmare');
const nightmare = Nightmare({show: true});
nightmare
.goto('https://www.linode.com/docs')
.insert('.ais-SearchBox-input', 'ubuntu')
.click('.ais-SearchBox-submit')
.wait('.ais-Hits-list')
.evaluate(function() {
let searchResults = [];
const results = document.querySelectorAll('a.c-search__result__link');
results.forEach(function(result) {
let row = {
'title':result.innerText,
'url':result.href
}
searchResults.push(row);
});
return searchResults;
})
.end()
.then(function(result) {
result.forEach(function(r) {
console.log('Title: ' + r.title);
console.log('URL: ' + r.url);
})
})
- Transform Your Workflow with This Easy-to-Run Script!
xvfb-run node linode.js
Explore the World of Ubuntu with the Linode Docs Page: See the Results and URLs Now!
The output will resemble the following:
Title: How to Install a LAMP Stack on Ubuntu 16.04
URL: https://www.linode.com/docs/web-servers/lamp/install-lamp-stack-on-ubuntu-16-04
Title: Install and Configure MySQL Workbench on Ubuntu 16.04
URL: https://www.linode.com/docs/databases/mysql/install-and-configure-mysql-workbench-on-ubuntu
Title: Install MongoDB on Ubuntu 16.04 (Xenial)
URL: https://www.linode.com/docs/databases/mongodb/install-mongodb-on-ubuntu-16-04
...
Take Control of Your Automation Process: Add a Cron Job to Run Your Script Now!
This example automates the script to run once every hour; it changes to the ~/automation/ directory, runs the scraping script, and thereby saves the output to a file with a unique filename that includes the date and time it ran. Consequently, this helps to ensure that the script runs regularly and the data it produces is easily identifiable and retrievable.
Unlock the Secrets of Time Management with Our Comprehensive Guide to Using Cron!
- Unlock the Secrets of Automation: Open the Crontab File!
crontab -e
- Complete Your File and Unlock Its Full Potential: Add the Following Line to the End of the File!
File: crontab
0 * * * * cd ~/automation && xvfb-run node linode.js >> data_$(date +\%Y_\%m_\%d_\%I_\%M_\%p).txt
Unveiling the Hidden: Discover More with Unprecedented Access to Information!
While these resources are provided in the hope of being helpful, it is important to note that their accuracy or timeliness cannot be vouched for. Therefore, if additional information on the topic is needed, one should consult these resources, yet with caution.