-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape_basic.py
More file actions
36 lines (27 loc) · 1.18 KB
/
Copy pathscrape_basic.py
File metadata and controls
36 lines (27 loc) · 1.18 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
"""Basic scraping examples using the AlterLab Python SDK."""
import asyncio
from alterlab import AlterLab, AdvancedOptions
async def main():
async with AlterLab(api_key="sk_test_...") as client:
# 1. Simple HTML scrape (fastest, ~1 credit)
result = await client.scrape("https://example.com")
print(f"Content length: {len(result['content'])} chars")
print(f"Credits used: {result['billing']['total_credits']}")
# 2. JavaScript rendering for dynamic pages
result = await client.scrape("https://example.com", mode="js")
print(f"JS-rendered content: {len(result['content'])} chars")
# 3. Get markdown output
result = await client.scrape(
"https://example.com",
formats=["markdown", "text"],
)
print(f"Markdown: {result['filtered_content']['markdown'][:200]}")
# 4. Screenshot capture
result = await client.scrape(
"https://example.com",
mode="js",
advanced=AdvancedOptions(render_js=True, screenshot=True),
)
print(f"Screenshot URL: {result.get('screenshot_url')}")
if __name__ == "__main__":
asyncio.run(main())