DEV Community

datalume
datalume

Posted on Edited on

How to Scrape a Public Telegram Channel in Python (2026): No API Key, No Login

Most "Telegram scraper" tutorials start with Telethon: create an app at my.telegram.org, log in with your phone number, keep a session file, and hope your personal account doesn't get flagged. For public channels you don't need any of that.

Every public channel has a web preview at https://t.me/s/<channel>. Open https://t.me/s/durov in a browser and you'll see the latest posts as plain HTML, no login. That page is all you need for text, dates, views, reactions and media.

This post shows the 30-line version, the traps I hit when I turned it into a production scraper, and the numbers from real runs.

The 30-line version

pip install requests beautifulsoup4
Enter fullscreen mode Exit fullscreen mode
import re
import requests
from bs4 import BeautifulSoup


def parse_count(s):
    """'985K' -> 985000, '4.71M' -> 4710000, '843' -> 843"""
    m = re.fullmatch(r"([\d.]+)([KMB]?)", (s or "").strip())
    if not m:
        return None
    return int(float(m[1]) * {"": 1, "K": 1e3, "M": 1e6, "B": 1e9}[m[2]])


def fetch_page(channel, before=None):
    url = f"https://t.me/s/{channel}" + (f"?before={before}" if before else "")
    html = requests.get(url, headers={"User-Agent": "Mozilla/5.0"}, timeout=20).text
    soup = BeautifulSoup(html, "html.parser")
    posts = []
    for br in soup.select(".tgme_widget_message_text br"):
        br.replace_with("\n")
    for msg in soup.select(".tgme_widget_message[data-post]"):
        text_el = msg.select_one(".tgme_widget_message_text")
        time_el = msg.select_one(".tgme_widget_message_date time[datetime]")
        views_el = msg.select_one(".tgme_widget_message_views")
        posts.append({
            "post": msg["data-post"],
            "date": time_el["datetime"] if time_el else None,
            "views": parse_count(views_el.text) if views_el else None,
            "text": text_el.get_text().strip() if text_el else "",
        })
    more = soup.select_one("a.tme_messages_more[data-before]")
    return posts, (more["data-before"] if more else None)


posts, before = fetch_page("durov")
print(len(posts), "posts, next page before =", before)
Enter fullscreen mode Exit fullscreen mode

On 18 November 2026 this returned 20 posts from durov, with views like 805K turned into 805000.

How the page works:

  • One page = 20 posts, oldest at the top, newest at the bottom.
  • Older posts: the page has a tme_messages_more link with data-before="N". Request ?before=N to get the 20 posts before post N.
  • Each post is a .tgme_widget_message element whose data-post is channel/number. That number is your stable post ID.
  • Channel search: ?q=keyword searches inside the channel (more on that below).
  • Channel that doesn't exist: you get redirected to t.me/<name> instead of a page with posts.

The traps

The 30-line version works for a demo. These are the things that broke when I ran it on real channels.

1. Reply previews end up in the text. When a post replies to another post, the quoted snippet is also a .tgme_widget_message_text element. select_one may grab the quote instead of the post. You have to skip text elements inside .tgme_widget_message_reply (and inside link previews).

2. Don't add separators when extracting text. Links, bold text and emoji are separate HTML elements inside a post, so get_text(" ", strip=True) or get_text("\n", strip=True) inserts spaces or line breaks in the middle of sentences. Turn <br> into newlines yourself and call get_text() without a separator, as above. On search pages this matters even more, because Telegram wraps each matched word in <mark>.

3. Counts are rounded strings. Views come as 985K, 4.71M or 11.7M, so you only ever get 3 significant digits. That's what Telegram shows; there is no exact number on the page.

4. "Only new posts" needs state. For monitoring you want each run to return only posts published since the last run. That means storing the newest post number per channel (and per search query) somewhere, and paging back until you reach it, without missing posts when more than 20 arrived.

5. Media is spread over several element types. Photos are CSS background-image URLs, videos have their own player element with a thumbnail and duration, and some large videos and documents are not on the web preview at all.

6. Reactions, forwards and paid Stars each have their own markup. Paid reactions (Telegram Stars) look like normal reactions with an extra class.

7. Not every channel has a preview. Private channels, invite links (t.me/+...), group chats and comments are not on t.me/s/.

None of these is hard on its own. Together they're the difference between a demo and something you can schedule every hour.

The hosted version

I run these fixes as an Apify Actor: Telegram Channel Scraper. It returns text, date, views, every reaction with its count, paid Stars, photos and videos, link previews, hashtags, mentions, forwards and replies, plus the subscriber count of the channel.

Real runs on 14 November 2026:

Input Result
durov + telegram, 20 posts each 40 posts in 4 seconds; text, date, views and reactions on 40/40
binance_announcements + durov + telegram 60 posts in 4 seconds
15 back-to-back requests 15/15 succeeded, no rate limiting

For monitoring there is an Only new posts switch that keeps the cursor for you. Pricing is per post, and a scheduled run that finds nothing new costs $0.00005, so an hourly check is close to free when the channel is quiet.

From Python:

from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("datalume/telegram-channel-scraper").call(run_input={
    "channels": ["durov", "telegram"],
    "maxPostsPerChannel": 50,
    "onlyNewPosts": True,
})
for post in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(post["date"], post["views"], (post["text"] or "")[:80])
Enter fullscreen mode Exit fullscreen mode

Or as a tool for Claude, Cursor or another MCP client: https://mcp.apify.com?tools=datalume/telegram-channel-scraper.

When to use which

  • A few channels, once: the 30-line version is fine. Add the reply-preview fix.
  • Scheduled monitoring, many channels, or you need reactions and media: use the hosted version or budget a day to handle the traps above.
  • Need posts that mention a keyword across channels you don't know yet? That's a different problem (you have to find the channels first): see How to Search Telegram for a Keyword Without Logging In.

I run datalume, a small set of public-data scrapers on Apify. This post was written with AI assistance; the numbers come from real runs on the dates shown. Not affiliated with Telegram.

Top comments (0)