Skip to content

About

Telegram Channel Scraper: Channel info, subscribers and recent messages

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Telegram Channel Scraper API by Scrapier

Telegram Channel Scraper for Python

Scrape a public Telegram channel to JSON: title, description, subscriber count and recent messages. Built on the Scrapier API: one HTTPS request, no headless browser to run, no parser to maintain.

tests Python 3.9+ Get a free API key

Quickstart · Fields · CLI · FAQ

Quickstart

  1. Get an API key from the Scrapier dashboard. No credit card needed to start.

  2. Install:

    pip install git+https://github.com/get-scrapier/Telegram-Channel-Scraper
  3. Run:

from scrapier_telegram_channel import TelegramChannel

client = TelegramChannel(api_key="sk_live_...")   # or set SCRAPIER_API_KEY

channel = client.channel("https://t.me/durov", page_size=100)
print(channel["title"], channel["subscribers"])
for message in channel["messages"]:   # note the nesting
    print(message)

The same code is in examples/quickstart.py.

Use cases

  • Community monitoring
  • News tracking
  • Brand monitoring
  • Market research

What it does

Reads a public Telegram channel -- the title, the description, the subscriber count, and a batch of its recent messages.

One request gets both the channel and its messages. It does not paginate, so page_size is how you ask for more.

Wraps the Scrapier telegram-channel endpoint.

Calling it

record = client.channel(url)   # a plain dict
page = client.channel_page(url)
page.item           # the same record
page.data           # the whole envelope

One request, one record. An input the API has no record for comes back as an empty dict rather than raising.

Fields you actually get back

Observed on live responses, not copied from a schema.

Field Notes
title, username, url identity
description the channel's about text
subscribers how many follow it
verified whether Telegram verified it
messages the recent messages, nested -- see the quirks
media_count, video_count, link_count what the channel posts, counted
profile_image the channel avatar
input_url, scraped_at echoes your input, and when

Options

Argument What it does
page_size How many recent messages to fetch. Defaults to 10. This is the wire's own max_items, renamed because max_items on these methods is the walk cap -- and since this endpoint does not paginate, this is the only way to get more messages.
scrape_timeout Seconds the server allows the page fetch, 5 to 120. Distinct from the client's own timeout, which bounds the HTTP request. The wire name is timeout.

Quirks worth knowing

The messages are nested under messages and this does not paginate. Measured live: next_cursor came back None, so there is no iter_ method and no way to walk back through a channel's history:

channel = client.channel('https://t.me/durov')
for message in channel['messages']:
    print(message)

page_size is the only lever on how many you get.

page_size defaults to 10, which is a very short window for an active channel. Raise it deliberately.

Only public channels. This reads the t.me web preview, which Telegram serves to anyone; a private channel or one with the preview disabled returns nothing useful. That is Telegram's choice, not a scrape failure.

media_count, video_count and link_count describe the fetched messages, not the channel's lifetime totals -- so they move with page_size.

Async

AsyncTelegramChannel exposes every method TelegramChannel does, with identical arguments.

import asyncio
from scrapier_telegram_channel import AsyncTelegramChannel

async def main():
    async with AsyncTelegramChannel() as client:
        rows = await client.channel(url)

asyncio.run(main())

Bulk jobs

For hundreds of inputs, submit one background job instead of paging:

job = client.bulk([...], max_items=1000)   # up to 10,000 per input
print(job.job_id, job.status)

rows = job.wait(timeout=1800, poll_interval=5)

Reattach from another process with client.job(job_id), then read job.data.

Submits are deduplicated server-side on the request parameters, so an identical submit returns the job the first one created — including when that job failed. Vary a parameter to force a fresh attempt.

Errors

Everything derives from ScrapierError, so one except can catch the lot while you still get to be specific when it matters.

from scrapier_telegram_channel import InsufficientCreditsError, RateLimitError, ScrapierError

try:
    rows = client.channel(url)
except InsufficientCreditsError as exc:
    print(f"out of credits: {exc.balance} left, {exc.required} needed")
except RateLimitError as exc:
    print(f"slow down for {exc.retry_after}s")
except ScrapierError as exc:
    print(f"something else: {exc}")
Exception When
ConfigurationError no API key, or a reserved parameter was passed
TransportError the request never got a response
BadRequestError 400 — bad input
AuthenticationError 401 — bad or missing key
InsufficientCreditsError 402 with a balance — carries .balance and .required
NotFoundError 404
RateLimitError 429 — carries .retry_after
ScrapeTimeoutError 504 — the scrape itself ran out of time
ServiceUnavailableError 503
ServerError 5xx
JobFailedError a bulk job finished in failed — carries .errors
APIError the base for anything with a status code

429, 503, 5xx and transport failures are retried automatically with jittered backoff that honours Retry-After. 400, 401, 404 and a 402 about your balance are not — retrying those only wastes time.

Command line

export SCRAPIER_API_KEY=sk_live_...

scrapier-telegram-channel <url>

JSON on stdout and nothing else, so it pipes. Global flags (--api-key, --base-url, --timeout, --jsonl, --indent) work anywhere on the line. Exit codes: 0 success, 2 usage or configuration, 3 API error.

Client reference

TelegramChannel(
    api_key=None,        # falls back to $SCRAPIER_API_KEY
    base_url=None,       # falls back to $SCRAPIER_BASE_URL, then the default
    timeout=150.0,
    max_retries=3,       # for 429/503/5xx and transport failures
    http_client=None,    # bring your own httpx.Client
)

The key is sent in the X-API-Key header only — never in a URL or a request body, so it will not end up in a proxy log.

Every call also accepts method="GET" if you would rather the parameters went in the query string, use_proxy=True to route the scrape through Scrapier's proxy pool, and raw_data=True to get the upstream payloads instead of parsed rows.

Python 3.9+. The only dependency is httpx. Ships py.typed.

FAQ

Is this Telegram Channel Scraper free?

The client code is MIT-licensed. It needs a Scrapier API key, and requests are billed in credits; failed requests are not billed. See pricing. You can start without a credit card.

Do I need proxies or a headless browser?

No. The scrape runs on Scrapier's servers and returns JSON.

How do I scrape in bulk?

Use bulk jobs: submit many inputs as one background job, then job.wait().

Can an AI agent use this?

Yes. See AGENTS.md, or connect the Scrapier MCP server.

More from Scrapier

180+ endpoints across 35+ platforms: browse them all.

Support

Open an issue or read the docs.

License

MIT. See LICENSE.

About

Telegram Channel Scraper: Channel info, subscribers and recent messages

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages