Catalog108 / challenges / api/sse/notifications

Server-Sent Events stream

intermediate Matching curriculum →

What this challenge teaches

Teaches: SSE: text/event-stream with `id:` / `event:` / `data:` lines separated by blank lines.

Expected output: GET /api/sse/notifications, parse the SSE protocol, extract the data payload.

Submit your scraper's JSON output to /challenges/api/sse/notifications/grade (grader endpoint is part of a later phase; URL is reserved now).

SSE returns text/event-stream with lines like id:, event:, data:, separated by a blank line. On shared hosting this endpoint emits one frame then closes, poll repeatedly to simulate the live stream.

# Parse SSE
import requests, json
with requests.get("https://practice.scrapingcentral.com/api/sse/notifications", stream=True) as r:
  event = {}
  for line in r.iter_lines(decode_unicode=True):
  if not line:
  if event.get("data"):
  payload = json.loads(event["data"])
  print(event.get("event", "message"), payload)
  event = {}
  elif ":" in line:
  k, v = line.split(":", 1)
  event[k.strip()] = v.strip()