1
2from apify import Actor
3
4import requests
5
6from bs4 import BeautifulSoup
7
8async def main():
9 async with Actor:
10
11 actor_input = await Actor.get_input() or {}
12 url = actor_input.get('url')
13
14
15 response = requests.get(url)
16
17
18 soup = BeautifulSoup(response.content, 'html.parser')
19
20
21 headings = []
22 for heading in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']):
23 heading_object = { 'level': heading.name, 'text': heading.text }
24 print('Extracted heading', heading_object)
25 headings.append(heading_object)
26
27
28 await Actor.push_data(headings)