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