-
-
Save AnderRV/289563313c88fe6d597a67f43e52bdf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
const cheerio = require('cheerio'); | |
const extractLinks = $ => [ | |
...new Set( | |
$('.page-numbers a') // Select pagination links | |
.map((_, a) => $(a).attr('href')) // Extract the href (url) from each link | |
.toArray() // Convert cheerio object to array | |
), | |
]; | |
axios.get('https://scrapeme.live/shop/').then(({ data }) => { | |
const $ = cheerio.load(data); // Initialize cheerio | |
const links = extractLinks($); | |
console.log(links); | |
// ['https://scrapeme.live/shop/page/2/', 'https://scrapeme.live/shop/page/3/', ... ] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment