Skip to content

Latest commit

 

History

History
164 lines (124 loc) · 3.83 KB

File metadata and controls

164 lines (124 loc) · 3.83 KB

TVMaze Scraper — Python usage

Call the hosted TVMaze Scraper Actor from Python with the official apify-client. This client talks to the Apify platform — no scraping code runs locally.

Install

pip install apify-client

Authenticate

Get your API token from https://apify.com/account/integrations. Prefer an environment variable over hard-coding it:

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

Run the actor and fetch results

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

# Search TV shows by name
run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "searchShows",
    "query": "breaking bad",
    "maxResults": 50,
})

# Iterate over dataset items
for show in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(f'{show["name"]} ({show.get("premiered")}) — rating {show.get("rating")}')

Example inputs per mode

Crawl the catalogue (showIndex)

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "showIndex",
    "startPage": 0,
    "maxResults": 5000,
})

Show details by ID batch, with cast (showDetails)

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "showDetails",
    "showIds": ["169", "82", "83"],
    "embedCast": True,
})

Every episode of a series (episodes)

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "episodes",
    "showId": "83",
    "maxResults": 2000,
})

Cast & characters (cast)

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "cast",
    "showId": "169",
})

Daily TV schedule (schedule)

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "schedule",
    "country": "US",
    "date": "2026-07-06",
})

People search or by ID (people)

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "people",
    "query": "bryan cranston",
    "maxResults": 20,
})

Collect all items into a list

run = client.actor("logiover/tvmaze-scraper").call(run_input={
    "mode": "episodes",
    "showId": "83",
})

items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
print(f"Fetched {len(items)} episodes")

Paginate explicitly

dataset_client = client.dataset(run["defaultDatasetId"])

offset = 0
limit = 1000
while True:
    page = dataset_client.list_items(offset=offset, limit=limit)
    for item in page.items:
        # process each show / episode / cast / schedule row
        pass
    offset += len(page.items)
    if offset >= page.total or not page.items:
        break

Start a run without waiting (fire-and-forget)

# .start() returns immediately with the run dict
run = client.actor("logiover/tvmaze-scraper").start(run_input={
    "mode": "showIndex",
    "maxResults": 20000,
})
print("Run started:", run["id"])

# Later, wait for it and read results:
finished = client.run(run["id"]).wait_for_finish()
items = list(client.dataset(finished["defaultDatasetId"]).iterate_items())

Export to CSV / Excel

# Download the dataset in a specific format as bytes
csv_bytes = client.dataset(run["defaultDatasetId"]).download_items(item_format="csv")
with open("tvmaze.csv", "wb") as f:
    f.write(csv_bytes)

xlsx_bytes = client.dataset(run["defaultDatasetId"]).download_items(item_format="xlsx")
with open("tvmaze.xlsx", "wb") as f:
    f.write(xlsx_bytes)

Supported formats include json, csv, xlsx, jsonl, and xml.


▶️ Run TVMaze Scraper on Apify · 📄 Documentation only.