A NodeJS Web Scrapper That Will Return Real-Time Information Based Upon Info Requested
First Things First
-
In your Project Folder run
npm init -y
or runnpm init
and put whatever you want in the requirements -
Run
npm i cheerio
andnpm i request
unless they are already installed
I am providing the following things.
-
a Default file to use
-
one Formated to Retrieve the Daily Pokemon + Episode Titles from the Pokemon Website a sample pretty much on how simple this is to use aswell
Default Code.
const request = require('request');
const cheerio = require('cheerio');
request('WEBSITE_URL_GOES_HERE', (error, Response, html) => {
if (!error) {
const $ = cheerio.load(html)
const HTML_TITLE_NAME = $('HTML_CLASS_WHICH_YOU_WANT_INFO_FROM');
console.log(HTML_TITLE_NAME)
}
})
Note
There is going to be whitespace in the console, in my opinion it was never a problem but seeing that it may be for others, you can simply just add this replace method in
replace(/\s\s+/g, '');