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({
33 "_id": "6613b694115ce0746526cace",
34 "index": 0,
35 "guid": "6b641c15-4525-4821-9e13-a1b80687a0c1",
36 "isActive": true,
37 "balance": "$2,274.85",
38 "picture": "http://placehold.it/32x32",
39 "age": 38,
40 "eyeColor": "green",
41 "name": "Thomas Carver",
42 "gender": "male",
43 "company": "ORBOID",
44 "email": "thomascarver@orboid.com",
45 "phone": "+1 (812) 467-3843",
46 "address": "310 Apollo Street, Strong, Missouri, 6644",
47 "about": "Adipisicing nisi ex magna nisi esse do non ea nulla tempor anim voluptate aliquip. Ut commodo ex magna velit. Aliqua do eiusmod qui mollit dolore dolor nulla voluptate voluptate ullamco ullamco quis. Voluptate amet ea culpa ut laborum enim elit cupidatat labore non consequat. Ut anim aliquip nulla ullamco reprehenderit enim ex.\r\n",
48 "registered": "2024-02-15T09:59:11 -01:00",
49 "latitude": 34.573829,
50 "longitude": -16.193091,
51 "tags": [
52 "exercitation",
53 "est",
54 "consequat",
55 "esse",
56 "mollit",
57 "reprehenderit",
58 "incididunt"
59 ],
60 "friends": [
61 {
62 "id": 0,
63 "name": "Kelsey Hayes"
64 },
65 {
66 "id": 1,
67 "name": "Kimberly Simmons"
68 },
69 {
70 "id": 2,
71 "name": "Nelda Pittman"
72 }
73 ],
74 "greeting": "Hello, Thomas Carver! You have 1 unread messages.",
75 "favoriteFruit": "strawberry"
76 });
77});
78
79
80await Actor.pushData(headings);
81
82
83await Actor.exit();