-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchained_extract.py
More file actions
63 lines (48 loc) · 1.54 KB
/
chained_extract.py
File metadata and controls
63 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Chained Multi-Step Extraction Example
This example demonstrates:
- Multi-step navigation workflows
- Combining captureText and captureList on the same page
- Building complex scraping pipelines
Site: BBC Sport — Premier League table (https://www.bbc.com/sport/football/tables)
"""
import asyncio
import json
import os
import sys
from dotenv import load_dotenv
from maxun import Extract, Config
async def main():
extractor = Extract(Config(
api_key=os.environ["MAXUN_API_KEY"],
base_url=os.environ.get("MAXUN_BASE_URL", "https://app.maxun.dev/api/sdk/"),
))
robot = await (
extractor
.create("Premier League Score Table")
.navigate("https://www.bbc.com/sport/football/tables")
.capture_text(
{"Title": "a#tab-PremierLeague"},
"Text Data",
)
.capture_list(
{
"selector": "tr.ssrcss-1urqilq-CellsRow.e13j9mpy2",
"maxItems": 10,
},
"Football Scores",
)
)
print(f"Robot created: {robot.id}")
result = await robot.run()
print("\n=== Featured Tab ===")
print(result.get("data", {}).get("textData"))
list_data = result.get("data", {}).get("listData") or []
print(f"\n=== League Table ({len(list_data)} rows) ===")
print("First 3 rows:")
print(json.dumps(list_data[:3], indent=2))
load_dotenv()
if not os.environ.get("MAXUN_API_KEY"):
print("Error: MAXUN_API_KEY environment variable is required", file=sys.stderr)
sys.exit(1)
asyncio.run(main())