telegram-channel-scraper 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- telegram_channel_scraper-2.0.0/LICENSE +21 -0
- telegram_channel_scraper-2.0.0/PKG-INFO +520 -0
- telegram_channel_scraper-2.0.0/README.md +462 -0
- telegram_channel_scraper-2.0.0/pyproject.toml +49 -0
- telegram_channel_scraper-2.0.0/setup.cfg +4 -0
- telegram_channel_scraper-2.0.0/telegram_channel_scraper.egg-info/PKG-INFO +520 -0
- telegram_channel_scraper-2.0.0/telegram_channel_scraper.egg-info/SOURCES.txt +29 -0
- telegram_channel_scraper-2.0.0/telegram_channel_scraper.egg-info/dependency_links.txt +1 -0
- telegram_channel_scraper-2.0.0/telegram_channel_scraper.egg-info/entry_points.txt +3 -0
- telegram_channel_scraper-2.0.0/telegram_channel_scraper.egg-info/requires.txt +23 -0
- telegram_channel_scraper-2.0.0/telegram_channel_scraper.egg-info/top_level.txt +2 -0
- telegram_channel_scraper-2.0.0/telegram_scraper.py +26 -0
- telegram_channel_scraper-2.0.0/tests/test_client.py +116 -0
- telegram_channel_scraper-2.0.0/tests/test_export_analytics_cli.py +93 -0
- telegram_channel_scraper-2.0.0/tests/test_live.py +61 -0
- telegram_channel_scraper-2.0.0/tests/test_mcp.py +44 -0
- telegram_channel_scraper-2.0.0/tests/test_parser.py +69 -0
- telegram_channel_scraper-2.0.0/tgscraper/__init__.py +93 -0
- telegram_channel_scraper-2.0.0/tgscraper/__main__.py +5 -0
- telegram_channel_scraper-2.0.0/tgscraper/analytics.py +130 -0
- telegram_channel_scraper-2.0.0/tgscraper/cli.py +265 -0
- telegram_channel_scraper-2.0.0/tgscraper/client.py +318 -0
- telegram_channel_scraper-2.0.0/tgscraper/dashboard.py +112 -0
- telegram_channel_scraper-2.0.0/tgscraper/exporters.py +163 -0
- telegram_channel_scraper-2.0.0/tgscraper/filters.py +80 -0
- telegram_channel_scraper-2.0.0/tgscraper/mcp_server.py +220 -0
- telegram_channel_scraper-2.0.0/tgscraper/media.py +58 -0
- telegram_channel_scraper-2.0.0/tgscraper/models.py +84 -0
- telegram_channel_scraper-2.0.0/tgscraper/monitor.py +93 -0
- telegram_channel_scraper-2.0.0/tgscraper/parser.py +240 -0
- telegram_channel_scraper-2.0.0/tgscraper/state.py +38 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Seyed Amir Hossein
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: telegram-channel-scraper
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Scrape public Telegram channels without API keys or login — Python library, CLI, MCP server for AI agents, and dashboard.
|
|
5
|
+
Author: specialteam
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Seyed Amir Hossein
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/specialteam/TelegramScraper
|
|
29
|
+
Project-URL: Issues, https://github.com/specialteam/TelegramScraper/issues
|
|
30
|
+
Keywords: telegram,scraper,telegram-scraper,telegram-channel,web-scraping,osint,mcp,mcp-server,model-context-protocol,ai-agent,claude,llm-tools,crawler,t.me
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
35
|
+
Classifier: Topic :: Communications :: Chat
|
|
36
|
+
Classifier: Environment :: Console
|
|
37
|
+
Classifier: Framework :: AsyncIO
|
|
38
|
+
Requires-Python: >=3.9
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: httpx[socks]>=0.27
|
|
42
|
+
Requires-Dist: beautifulsoup4>=4.11
|
|
43
|
+
Provides-Extra: excel
|
|
44
|
+
Requires-Dist: openpyxl>=3.1; extra == "excel"
|
|
45
|
+
Provides-Extra: mcp
|
|
46
|
+
Requires-Dist: mcp>=1.2; python_version >= "3.10" and extra == "mcp"
|
|
47
|
+
Provides-Extra: dashboard
|
|
48
|
+
Requires-Dist: streamlit>=1.35; extra == "dashboard"
|
|
49
|
+
Provides-Extra: all
|
|
50
|
+
Requires-Dist: telegram-channel-scraper[dashboard,excel,mcp]; extra == "all"
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: telegram-channel-scraper[excel,mcp]; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
54
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
55
|
+
Requires-Dist: respx>=0.21; extra == "dev"
|
|
56
|
+
Requires-Dist: flake8; extra == "dev"
|
|
57
|
+
Dynamic: license-file
|
|
58
|
+
|
|
59
|
+
<div align="center">
|
|
60
|
+
|
|
61
|
+
# 📡 Telegram Scraper
|
|
62
|
+
|
|
63
|
+
**Scrape, search, monitor and analyze any public Telegram channel — no API key, no login, no phone number.**
|
|
64
|
+
|
|
65
|
+
Python library · CLI · MCP server for AI agents · Claude Skill · Web dashboard · Docker
|
|
66
|
+
|
|
67
|
+
[](https://github.com/specialteam/TelegramScraper/actions)
|
|
68
|
+
[](https://pypi.org/project/telegram-channel-scraper/)
|
|
69
|
+

|
|
70
|
+

|
|
71
|
+

|
|
72
|
+
|
|
73
|
+
[Quick start](#-quick-start) · [CLI](#-command-line) · [Python](#-python-library) · [AI / MCP](#-use-it-from-ai-assistants-mcp--skill) · [Dashboard](#-web-dashboard) · [فارسی](#-راهنمای-فارسی)
|
|
74
|
+
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install "telegram-channel-scraper[all]"
|
|
79
|
+
tgscraper durov
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
That's it — the latest posts of `t.me/durov`, in your terminal.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## ✨ Features
|
|
87
|
+
|
|
88
|
+
| | |
|
|
89
|
+
|---|---|
|
|
90
|
+
| 🔓 **Zero setup** | Uses the public web preview `t.me/s/<channel>`. No `api_id`, no session files, no account ban risk. |
|
|
91
|
+
| 🧾 **Rich data** | id, date, text, HTML, views, reactions, author, edited, forwards, replies, photos, videos, voice, documents, link previews, hashtags, mentions, links. |
|
|
92
|
+
| 🔎 **Search & filters** | Telegram's server-side search, date ranges, keywords, regex, hashtags, media type, minimum views. |
|
|
93
|
+
| 💾 **Export anywhere** | JSON, JSON Lines, CSV (Excel-friendly UTF-8), Excel `.xlsx`, SQLite (upsert archive), Markdown. |
|
|
94
|
+
| ⚡ **Fast & robust** | Async + concurrent multi-channel scraping, retries with backoff, `Retry-After` handling, rate limiting, rotating HTTP/SOCKS proxies. |
|
|
95
|
+
| 🔁 **Incremental** | Remembers the last post per channel — the next run fetches only new posts. |
|
|
96
|
+
| 👀 **Monitor** | Watch channels and push new posts to a webhook (Slack, Discord, n8n…) or a Telegram bot. |
|
|
97
|
+
| 🖼 **Media download** | Save photos, videos and voice notes of any post. |
|
|
98
|
+
| 📊 **Analytics** | Top posts, posting frequency by day/hour/weekday, hashtags, top words, reactions, EN/FA sentiment. |
|
|
99
|
+
| 🤖 **AI-native** | MCP server with 8 tools, a ready-made Claude Skill, and `--json` output for every command. |
|
|
100
|
+
| 🖥 **Dashboard** | Streamlit UI with charts and one-click export. |
|
|
101
|
+
| 🐳 **Docker** | Run the CLI, the dashboard or a 24/7 monitor in a container. |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🚀 Quick start
|
|
106
|
+
|
|
107
|
+
### Install
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# everything (CLI + Excel + MCP server + dashboard)
|
|
111
|
+
pip install "telegram-channel-scraper[all]"
|
|
112
|
+
|
|
113
|
+
# or minimal (CLI + library only: httpx + beautifulsoup4)
|
|
114
|
+
pip install telegram-channel-scraper
|
|
115
|
+
|
|
116
|
+
# or from a clone
|
|
117
|
+
git clone https://github.com/specialteam/TelegramScraper && cd TelegramScraper && pip install -e ".[all]"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Three ways to use it
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
tgscraper durov -n 100 -o durov.csv # 1. command line
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import tgscraper as tg # 2. Python
|
|
128
|
+
posts = tg.scrape("durov", limit=100)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
"What did @durov post this week?" # 3. ask your AI assistant (MCP / Skill)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 💻 Command line
|
|
138
|
+
|
|
139
|
+
Anything that looks like a channel works: `durov`, `@durov`, `t.me/durov`, `https://t.me/s/durov`.
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
tgscraper durov # latest 20 posts, pretty output
|
|
143
|
+
tgscraper durov -n 500 -o durov.xlsx # save (.json .jsonl .csv .xlsx .db .md)
|
|
144
|
+
tgscraper durov -n 0 -o full_history.db # the whole channel history (-n 0 = no limit)
|
|
145
|
+
tgscraper durov telegram tginfo -n 50 -o all.db # several channels into one SQLite file
|
|
146
|
+
|
|
147
|
+
tgscraper durov --since 2026-01-01 --until 2026-01-31
|
|
148
|
+
tgscraper durov -n 300 -k ton -k bitcoin # keyword filter (any of them)
|
|
149
|
+
tgscraper durov --regex "v\d+\.\d+" # regex filter
|
|
150
|
+
tgscraper durov --hashtag news --min-views 50000
|
|
151
|
+
tgscraper durov --media-only --media-type video
|
|
152
|
+
|
|
153
|
+
tgscraper search durov "privacy" -n 30 # Telegram's own full-history search
|
|
154
|
+
tgscraper info durov # title, description, subscribers, counters
|
|
155
|
+
tgscraper stats durov -n 300 # analytics report (or: tgscraper stats durov.json)
|
|
156
|
+
tgscraper media durov -n 50 -d ./media # download photos & videos
|
|
157
|
+
tgscraper durov --incremental -o archive.db # only posts newer than the last run
|
|
158
|
+
|
|
159
|
+
tgscraper watch durov telegram -i 120 # print new posts live
|
|
160
|
+
tgscraper watch durov --webhook https://hooks.slack.com/services/... # push to a webhook
|
|
161
|
+
tgscraper watch durov -k airdrop --bot-token 123:ABC --chat-id 42 # alert via your Telegram bot
|
|
162
|
+
|
|
163
|
+
tgscraper durov --json | jq '.[] | {url, views}' # machine-readable output for scripts & agents
|
|
164
|
+
tgscraper durov -p socks5://127.0.0.1:1080 # proxy (repeat -p to rotate several)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
<details>
|
|
168
|
+
<summary><b>Example: <code>tgscraper stats</code> (illustrative output)</b></summary>
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
📊 300 messages from durov
|
|
172
|
+
2025-03-02T10:14:00+00:00 → 2026-09-20T16:40:00+00:00 (1.3 posts/day)
|
|
173
|
+
👁 total views 412,905,120 · average 1,376,350
|
|
174
|
+
📎 with media 121 {'photo': 88, 'video': 33} · forwarded 4
|
|
175
|
+
🙂 sentiment avg +0.21 (+97 / =180 / -23)
|
|
176
|
+
|
|
177
|
+
🔥 Top posts:
|
|
178
|
+
4,812,000 https://t.me/durov/301 'Telegram now has ...'
|
|
179
|
+
...
|
|
180
|
+
🕒 Posts by hour (UTC):
|
|
181
|
+
14 ██████████████ 41
|
|
182
|
+
15 ██████████████████████████████ 87
|
|
183
|
+
```
|
|
184
|
+
</details>
|
|
185
|
+
|
|
186
|
+
Run `tgscraper --help` or `tgscraper <command> --help` for every option.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 🐍 Python library
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
import tgscraper as tg
|
|
194
|
+
|
|
195
|
+
# Channel info
|
|
196
|
+
info = tg.channel_info("durov")
|
|
197
|
+
print(info.title, info.subscribers, info.description)
|
|
198
|
+
|
|
199
|
+
# Latest posts — list of Message objects, newest first
|
|
200
|
+
posts = tg.scrape("durov", limit=100)
|
|
201
|
+
for p in posts:
|
|
202
|
+
print(p.date, p.views, p.url, p.text[:80], p.media_types, p.reactions)
|
|
203
|
+
|
|
204
|
+
# Filters (all optional, combine freely)
|
|
205
|
+
posts = tg.scrape(
|
|
206
|
+
"durov", limit=None, # None = whole history
|
|
207
|
+
since="2026-01-01", until="2026-06-30",
|
|
208
|
+
keywords=["ton", "wallet"], regex=r"\bv\d+", hashtag="update",
|
|
209
|
+
media_only=True, media_types=["photo"], min_views=100_000,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
tg.search("durov", "privacy", limit=20) # Telegram server-side search
|
|
213
|
+
tg.get_message("durov", 123) # one post
|
|
214
|
+
tg.scrape("durov", incremental=True) # only new posts since last incremental call
|
|
215
|
+
|
|
216
|
+
# Many channels concurrently
|
|
217
|
+
results = tg.scrape_many(["durov", "telegram", "tginfo"], limit=200) # {channel: [Message] | Exception}
|
|
218
|
+
|
|
219
|
+
# Export / load
|
|
220
|
+
tg.export(posts, "posts.xlsx") # .json .jsonl .csv .xlsx .db .md
|
|
221
|
+
posts = tg.load("posts.json") # from .json .jsonl .db
|
|
222
|
+
|
|
223
|
+
# Analytics
|
|
224
|
+
stats = tg.summarize(posts) # JSON-friendly dict
|
|
225
|
+
print(tg.format_summary(stats))
|
|
226
|
+
tg.sentiment("Great news, bullish!") # -1 .. 1 (EN + FA lexicon)
|
|
227
|
+
|
|
228
|
+
# Media
|
|
229
|
+
tg.download_media(posts, "media/", types=["photo", "video"])
|
|
230
|
+
|
|
231
|
+
# Monitor forever
|
|
232
|
+
tg.watch(["durov"], [tg.webhook_notifier("https://example.com/hook"), print], interval=60)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
<details>
|
|
236
|
+
<summary><b>Advanced: reusable / async clients, proxies, streaming</b></summary>
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from tgscraper import Scraper, AsyncScraper, MessageFilter
|
|
240
|
+
|
|
241
|
+
with Scraper(proxies=["socks5://p1:1080", "http://p2:8080"], timeout=20, retries=3, delay=0.5) as s:
|
|
242
|
+
for msg in s.iter_messages("durov", limit=None, filter=MessageFilter(since="2026-01-01")):
|
|
243
|
+
print(msg.id) # streams page by page, low memory
|
|
244
|
+
|
|
245
|
+
async with AsyncScraper(concurrency=10) as s:
|
|
246
|
+
posts = await s.get_messages("durov", 1000)
|
|
247
|
+
async for msg in s.iter_messages("telegram", 50, query="stories"):
|
|
248
|
+
...
|
|
249
|
+
```
|
|
250
|
+
</details>
|
|
251
|
+
|
|
252
|
+
### Message fields
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"id": 123, "channel": "durov", "url": "https://t.me/durov/123",
|
|
257
|
+
"date": "2026-01-10T09:30:00+00:00", "text": "…", "html": "…",
|
|
258
|
+
"views": 1250000, "author": null, "edited": false,
|
|
259
|
+
"forwarded_from": null, "reply_to": 120,
|
|
260
|
+
"media": [{"type": "photo", "url": "https://cdn4.telesco.pe/…jpg", "thumbnail": "…", "duration": null, "title": null}],
|
|
261
|
+
"reactions": {"👍": 15000, "🔥": 3200},
|
|
262
|
+
"hashtags": ["news"], "mentions": ["telegram"], "links": ["https://telegram.org/blog"]
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Media types: `photo`, `video`, `round_video`, `voice`, `audio`, `document`, `sticker`, `link_preview`.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 🤖 Use it from AI assistants (MCP + Skill)
|
|
271
|
+
|
|
272
|
+
Telegram Scraper ships an **[MCP](https://modelcontextprotocol.io) server**, so Claude, Cursor, VS Code Copilot,
|
|
273
|
+
Windsurf, ChatGPT and any MCP client can read Telegram channels for you.
|
|
274
|
+
|
|
275
|
+
```mermaid
|
|
276
|
+
flowchart LR
|
|
277
|
+
U["You: 'Summarize @durov this week'"] --> AI[AI assistant]
|
|
278
|
+
AI -- MCP tools --> S[tgscraper-mcp]
|
|
279
|
+
S -- HTTPS --> T["t.me/s/durov"]
|
|
280
|
+
S -- JSON --> AI --> A[Answer with links & stats]
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### MCP tools
|
|
284
|
+
|
|
285
|
+
| Tool | What it does |
|
|
286
|
+
|---|---|
|
|
287
|
+
| `get_channel_info` | Title, description, subscribers, photo, media counters |
|
|
288
|
+
| `get_messages` | Latest posts with filters (dates, keywords, hashtag, media, views, paging with `before_id`) |
|
|
289
|
+
| `search_messages` | Full-history search inside a channel |
|
|
290
|
+
| `get_message` | One post by id (for `t.me/<channel>/<id>` links) |
|
|
291
|
+
| `get_new_messages` | Only posts newer than an id — follow a channel over time |
|
|
292
|
+
| `analyze_channel` | Stats: top posts, activity, hours, hashtags, words, reactions, sentiment |
|
|
293
|
+
| `compare_channels` | Side-by-side: subscribers, posts/day, avg views, engagement rate |
|
|
294
|
+
| `export_messages` | Save posts to a local `.json/.csv/.xlsx/.db/.md` file |
|
|
295
|
+
|
|
296
|
+
Plus prompts `summarize_channel` and `track_topic`, and the resource `telegram://channel/{channel}`.
|
|
297
|
+
|
|
298
|
+
### Connect it
|
|
299
|
+
|
|
300
|
+
The only requirement is [uv](https://docs.astral.sh/uv/) (`pip install uv`) — `uvx` downloads and runs the server
|
|
301
|
+
on demand. Or `pip install "telegram-channel-scraper[mcp]"` and use `"command": "tgscraper-mcp"` with no args.
|
|
302
|
+
|
|
303
|
+
<details open>
|
|
304
|
+
<summary><b>Claude Code</b></summary>
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
claude mcp add telegram-scraper -- uvx --from "telegram-channel-scraper[mcp]" tgscraper-mcp
|
|
308
|
+
```
|
|
309
|
+
Inside this repository it is automatic: [`.mcp.json`](https://github.com/specialteam/TelegramScraper/blob/main/.mcp.json) registers the server and
|
|
310
|
+
[`.claude/skills/telegram-scraper`](https://github.com/specialteam/TelegramScraper/blob/main/.claude/skills/telegram-scraper/SKILL.md) loads the skill.
|
|
311
|
+
</details>
|
|
312
|
+
|
|
313
|
+
<details>
|
|
314
|
+
<summary><b>Claude Desktop</b> · <b>Cursor</b> · <b>Windsurf</b> · any JSON-configured client</summary>
|
|
315
|
+
|
|
316
|
+
Add to `claude_desktop_config.json` (Settings → Developer → Edit config), `~/.cursor/mcp.json`,
|
|
317
|
+
or `~/.codeium/windsurf/mcp_config.json`:
|
|
318
|
+
|
|
319
|
+
```json
|
|
320
|
+
{
|
|
321
|
+
"mcpServers": {
|
|
322
|
+
"telegram-scraper": {
|
|
323
|
+
"command": "uvx",
|
|
324
|
+
"args": ["--from", "telegram-channel-scraper[mcp]", "tgscraper-mcp"],
|
|
325
|
+
"env": { "TGSCRAPER_PROXY": "" }
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
</details>
|
|
331
|
+
|
|
332
|
+
<details>
|
|
333
|
+
<summary><b>VS Code (Copilot agent mode)</b></summary>
|
|
334
|
+
|
|
335
|
+
`.vscode/mcp.json`:
|
|
336
|
+
```json
|
|
337
|
+
{
|
|
338
|
+
"servers": {
|
|
339
|
+
"telegram-scraper": {
|
|
340
|
+
"type": "stdio",
|
|
341
|
+
"command": "uvx",
|
|
342
|
+
"args": ["--from", "telegram-channel-scraper[mcp]", "tgscraper-mcp"]
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
</details>
|
|
348
|
+
|
|
349
|
+
<details>
|
|
350
|
+
<summary><b>Remote / HTTP (ChatGPT connectors, n8n, other hosts)</b></summary>
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
tgscraper mcp --transport streamable-http # serves MCP over HTTP
|
|
354
|
+
```
|
|
355
|
+
</details>
|
|
356
|
+
|
|
357
|
+
Environment variables: `TGSCRAPER_PROXY` (proxy URL for all requests), `TGSCRAPER_MCP_MAX_LIMIT` (default 500).
|
|
358
|
+
|
|
359
|
+
### Claude Skill
|
|
360
|
+
|
|
361
|
+
[`.claude/skills/telegram-scraper/SKILL.md`](https://github.com/specialteam/TelegramScraper/blob/main/.claude/skills/telegram-scraper/SKILL.md) teaches an agent when and how
|
|
362
|
+
to use the CLI (commands, JSON schema, how to cite results). Install it for all your projects:
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
mkdir -p ~/.claude/skills && cp -r .claude/skills/telegram-scraper ~/.claude/skills/
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
For claude.ai, zip the `telegram-scraper` folder and upload it under **Settings → Capabilities → Skills**.
|
|
369
|
+
|
|
370
|
+
**Try asking:**
|
|
371
|
+
- *"What are the 5 most viewed posts on @durov this year?"*
|
|
372
|
+
- *"Compare the engagement of these three crypto channels: …"*
|
|
373
|
+
- *"Search @xyz for 'airdrop' and give me the dates and links."*
|
|
374
|
+
- *"Export the last 1000 posts of t.me/abc to Excel."*
|
|
375
|
+
|
|
376
|
+
Other agents: [`AGENTS.md`](https://github.com/specialteam/TelegramScraper/blob/main/AGENTS.md) and [`llms.txt`](https://github.com/specialteam/TelegramScraper/blob/main/llms.txt) describe the project for LLMs.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## 🖥 Web dashboard
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
pip install "telegram-channel-scraper[dashboard]"
|
|
384
|
+
tgscraper dashboard # → http://localhost:8501
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Channel metrics, posts table with links, activity/views charts, top words & hashtags, CSV/JSON/Markdown download.
|
|
388
|
+
|
|
389
|
+
## 🐳 Docker
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
docker build -t tgscraper .
|
|
393
|
+
docker run --rm -v "$PWD/data:/data" tgscraper durov -n 100 -o durov.csv
|
|
394
|
+
docker compose up dashboard # dashboard on :8501
|
|
395
|
+
docker compose --profile watch up -d watch # 24/7 monitor archiving to data/archive.db
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## ❓ FAQ
|
|
401
|
+
|
|
402
|
+
**Does it need a Telegram account or API key?** No. It reads the same public page you see at `https://t.me/s/durov`.
|
|
403
|
+
|
|
404
|
+
**Which channels work?** Public channels with web preview enabled. Private channels, groups, DMs and bots don't have a
|
|
405
|
+
public preview — use [Telethon](https://github.com/LonamiWebs/Telethon) for those.
|
|
406
|
+
|
|
407
|
+
**`ChannelNotFound`?** The name is wrong, the channel is private, or its owner disabled the web preview.
|
|
408
|
+
|
|
409
|
+
**Getting HTTP 429 / blocked?** The scraper already retries with backoff. Increase `delay`, lower concurrency, or
|
|
410
|
+
rotate proxies (`-p` multiple times). In regions where Telegram is filtered, use `-p socks5://…`.
|
|
411
|
+
|
|
412
|
+
**Can I get comments / member lists?** No — they are not part of the public preview.
|
|
413
|
+
|
|
414
|
+
**How accurate is sentiment?** It's a small English/Persian word list: good for trends, not for single posts.
|
|
415
|
+
|
|
416
|
+
## 🧑💻 Development
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
pip install -e ".[dev]"
|
|
420
|
+
pytest -q # offline tests with HTML fixtures, no network needed
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
Project layout:
|
|
424
|
+
|
|
425
|
+
```
|
|
426
|
+
tgscraper/
|
|
427
|
+
client.py Scraper / AsyncScraper: paging, retries, proxies
|
|
428
|
+
parser.py t.me/s HTML → Message / Channel
|
|
429
|
+
models.py Message, Media, Channel dataclasses
|
|
430
|
+
filters.py MessageFilter
|
|
431
|
+
exporters.py json, jsonl, csv, xlsx, sqlite, md
|
|
432
|
+
analytics.py summarize(), sentiment()
|
|
433
|
+
monitor.py watch() + webhook / Telegram bot notifiers
|
|
434
|
+
media.py download_media()
|
|
435
|
+
state.py incremental state
|
|
436
|
+
cli.py `tgscraper` command
|
|
437
|
+
mcp_server.py `tgscraper-mcp` MCP server
|
|
438
|
+
dashboard.py Streamlit app
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
The old `from telegram_scraper import TelegramScraper` API still works.
|
|
442
|
+
|
|
443
|
+
## ⚖️ Responsible use
|
|
444
|
+
|
|
445
|
+
Only public data is accessed. Respect Telegram's Terms of Service, local laws and people's privacy; keep request
|
|
446
|
+
rates reasonable. This project is not affiliated with Telegram.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## 🇮🇷 راهنمای فارسی
|
|
451
|
+
|
|
452
|
+
<div dir="rtl">
|
|
453
|
+
|
|
454
|
+
**Telegram Scraper** ابزاری برای خواندن، جستوجو، مانیتور و تحلیل **کانالهای عمومی تلگرام** است؛ بدون API،
|
|
455
|
+
بدون لاگین و بدون شماره تلفن.
|
|
456
|
+
|
|
457
|
+
### نصب
|
|
458
|
+
|
|
459
|
+
</div>
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
pip install "telegram-channel-scraper[all]"
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
<div dir="rtl">
|
|
466
|
+
|
|
467
|
+
### مهمترین دستورها
|
|
468
|
+
|
|
469
|
+
</div>
|
|
470
|
+
|
|
471
|
+
```bash
|
|
472
|
+
tgscraper durov # ۲۰ پست آخر
|
|
473
|
+
tgscraper durov -n 500 -o durov.xlsx # ذخیره در اکسل (یا csv / json / db / md)
|
|
474
|
+
tgscraper durov --since 2026-01-01 -k بیتکوین
|
|
475
|
+
tgscraper search durov "privacy" # جستوجو در کل تاریخچه
|
|
476
|
+
tgscraper info durov # اطلاعات و تعداد اعضای کانال
|
|
477
|
+
tgscraper stats durov -n 300 # آمار: پربازدیدها، ساعتهای فعالیت، هشتگها، احساسات
|
|
478
|
+
tgscraper media durov -d ./media # دانلود عکس و ویدیو
|
|
479
|
+
tgscraper watch durov --bot-token TOKEN --chat-id ID # اعلان پست جدید با ربات تلگرام
|
|
480
|
+
tgscraper durov -p socks5://127.0.0.1:1080 # استفاده از پراکسی
|
|
481
|
+
tgscraper dashboard # داشبورد وب
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
<div dir="rtl">
|
|
485
|
+
|
|
486
|
+
### پایتون
|
|
487
|
+
|
|
488
|
+
</div>
|
|
489
|
+
|
|
490
|
+
```python
|
|
491
|
+
import tgscraper as tg
|
|
492
|
+
posts = tg.scrape("durov", limit=100, since="2026-01-01")
|
|
493
|
+
tg.export(posts, "posts.csv")
|
|
494
|
+
print(tg.format_summary(tg.summarize(posts)))
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
<div dir="rtl">
|
|
498
|
+
|
|
499
|
+
### اتصال به هوش مصنوعی
|
|
500
|
+
|
|
501
|
+
- **MCP:** با تنظیمات بخش [AI / MCP](#-use-it-from-ai-assistants-mcp--skill) به Claude، Cursor، VS Code و … وصل
|
|
502
|
+
کنید. بعد کافی است بپرسید: «پربازدیدترین پستهای این هفتهی @durov چی بوده؟»
|
|
503
|
+
- **Skill:** پوشهی `.claude/skills/telegram-scraper` را در `~/.claude/skills/` کپی کنید.
|
|
504
|
+
- خروجی همهی دستورها با `--json` برای ایجنتها و اسکریپتها قابل خواندن است.
|
|
505
|
+
|
|
506
|
+
فقط کانالهایی که پیشنمایش وب (`t.me/s/...`) دارند پشتیبانی میشوند. در ایران برای دسترسی از پراکسی استفاده کنید.
|
|
507
|
+
|
|
508
|
+
</div>
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
<div align="center">
|
|
513
|
+
|
|
514
|
+
MIT License · If this project helps you, give it a ⭐
|
|
515
|
+
|
|
516
|
+
<sub>Keywords: telegram scraper, telegram channel scraper, scrape telegram without api, t.me scraper, telegram
|
|
517
|
+
crawler, telegram osint, telegram to csv, telegram to excel, telegram monitor, telegram mcp server, mcp telegram,
|
|
518
|
+
claude telegram, ai agent telegram tool, python telegram scraper, اسکرپر تلگرام, استخراج پیام کانال تلگرام</sub>
|
|
519
|
+
|
|
520
|
+
</div>
|