Skip to content

Instantly share code, notes, and snippets.

@matefs
Created January 15, 2023 17:26
Show Gist options
  • Save matefs/f804e5604926551e6591707e78ae0e44 to your computer and use it in GitHub Desktop.
Save matefs/f804e5604926551e6591707e78ae0e44 to your computer and use it in GitHub Desktop.
Simple Nodejs webscrapper with axios express and cheerio
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.get('/scrape', (req, res) => {
axios.get('https://www.reddit.com/r/webdev/')
.then(response => {
const $ = cheerio.load(response.data);
const titles = [];
$('p.title').each((i, elem) => {
titles[i] = $(elem).text();
});
res.send(titles);
})
.catch(error => {
console.log(error);
});
});
app.listen(3000, () => {
console.log('Example app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment