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