1
2import axios from "axios";
3
4import * as cheerio from "cheerio";
5
6import { Actor } from "apify";
7
8
9await Actor.init();
10
11
12const input = await Actor.getInput();
13const { url } = input;
14
15
16const response = await axios.get(url);
17
18
19const $ = cheerio.load(response.data);
20
21
22const headings = [];
23$("h1, h2, h3, h4, h5, h6").each((i, element) => {
24 const headingObject = {
25 level: $(element).prop("tagName").toLowerCase(),
26 text: $(element).text(),
27 };
28 console.log("Extracted heading", headingObject);
29 headings.push(headingObject);
30});
31
32
33await Actor.pushData(headings);
34
35
36await Actor.exit();