Skip to content

Instantly share code, notes, and snippets.

@Frenzycore
Created December 23, 2025 05:29
Show Gist options
  • Select an option

  • Save Frenzycore/3af6ef5de364a62f0e09994b49d3e9e4 to your computer and use it in GitHub Desktop.

Select an option

Save Frenzycore/3af6ef5de364a62f0e09994b49d3e9e4 to your computer and use it in GitHub Desktop.
scraper for site https://www.example.com
import axios from "axios";
import * as cheerio from "cheerio";
async function example() {
try {
const { data: html } = await axios.get('https://www.example.com/', {
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' }
});
const $ = cheerio.load(html);
const pageContainer = $('div');
const mainParagraph = pageContainer.find('p').first();
const mainHeading = pageContainer.find('h1').text().trim();
const description = mainParagraph.contents().first().text().trim();
const linkElement = mainParagraph.find('a');
return {
mainHeading,
description,
moreInfoLink: {
text: linkElement.text().trim(),
url: linkElement.attr('href')
}
};
} catch (error) {
throw new Error(`Scraping failed: ${error.message}`);
}
}
export { example };
// 4:29 -- https://github.com/Frenzycore --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment