-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocialblade_profile_scraper.py
More file actions
41 lines (28 loc) · 1.04 KB
/
Copy pathsocialblade_profile_scraper.py
File metadata and controls
41 lines (28 loc) · 1.04 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
"""Run Social Blade Multi-Platform Analytics Scraper with the sample input."""
from __future__ import annotations
import json
import os
from pathlib import Path
from typing import Any
from apify_client import ApifyClient
ACTOR_ID = "datascraperes/socialblade-scraper"
INPUT_PATH = Path(__file__).parents[2] / "data" / "sample-input.json"
def _dataset_id(run: Any) -> str:
value = getattr(run, "default_dataset_id", None)
if value:
return value
value = getattr(run, "defaultDatasetId", None)
if value:
return value
return run["defaultDatasetId"]
def main() -> None:
token = os.environ.get("APIFY_API_TOKEN")
if not token:
raise SystemExit("Set APIFY_API_TOKEN before running this example.")
run_input = json.loads(INPUT_PATH.read_text(encoding="utf-8"))
client = ApifyClient(token)
run = client.actor(ACTOR_ID).call(run_input=run_input)
for item in client.dataset(_dataset_id(run)).iterate_items():
print(json.dumps(item, ensure_ascii=False))
if __name__ == "__main__":
main()