1
2import axios from 'axios';
3
4import * as cheerio from 'cheerio';
5
6import { Actor } from 'apify';
7
8
9
10
11
12
13
14await Actor.init();
15
16interface Input {
17 url: string;
18}
19
20const input = await Actor.getInput<Input>();
21if (!input) throw new Error("Input is missing!");
22const { url } = input;
23
24
25const response = await axios.get(url);
26
27
28const $ = cheerio.load(response.data);
29
30
31const headings: { level: string, text: string }[] = [];
32$("h1, h2, h3, h4, h5, h6").each((_i, element) => {
33 const headingObject = {
34 level: $(element).prop("tagName").toLowerCase(),
35 text: $(element).text(),
36 };
37 console.log("Extracted heading", headingObject);
38 headings.push(headingObject);
39});
40
41
42await Actor.pushData(headings);
43
44
45await Actor.exit();