Web Scraper with Vanilla Node JS | Node JS Tutorial

preview_player
Показать описание
#shorts

In this quick tutorial, I want to show how easy it is to create a very basic web scraper with Vanilla Node JS!

#javascript #nodejs #webscaping #webscraper #nodejsTutorials #coding

Hope that someone found this useful for his projects!

--- Useful links ---

Source Code:

Node JS string_decoder module docs:

Node JS HTTPS module docs:
Рекомендации по теме
Комментарии
Автор

Source Code:
// Dependencies
const https = require('https');
const stringDecoder =

// BufferString
const bufferString = function(url, callback){
https.get(url, function(req){
let buffer = '';
let decoder = new stringDecoder();
req.on('data', function(data){
buffer += decoder.write(data);
})
req.on('end', function(){
buffer += decoder.end();
callback(buffer);
})
})
}

// Count keyword function
const countKeyword = function(url, keyword){
const word = keyword;
bufferString(url, function(buffer){
const counter = countOccurences(buffer, word);
function countOccurences(string, word){
return string.split(word).length - 1;
}
console.log(`The web page contain ${counter} times "${word}"`);
})
}

// Get all links from a website
const allLinks = function(url){
bufferString(url, function(buffer){
let str = buffer;
let pattern =

console.log(match[1]);
}
})
}

// Get all links from a website
const viewSource = function(url){
bufferString(url, function(buffer){
let str = buffer;
console.log(str);
})
}

kungfucoding