Skip to main content

Scrape Telegram public channels (Python library + CLI)

Project description

tchan - Telegram Channel scraper

Python library and command-line interface to scrape Telegram public channels. Since this scraper uses Telegram Channel Web preview, it won't work for:

  • Public channels with "Restrict saving content" option enabled
  • Private channels
  • Public Groups
  • Private Groups

It's also not possible to retrieve comments, since they're made on a group.

Installing

pip install tchan  # Python library only
pip install tchan[cli]  # Library + CLI

Using as a libray

from tchan import ChannelScraper

scraper = ChannelScraper()
for message in scraper.messages("tchantest"):
    print(f"New message ({message.type}) from {message.channel}:")
    print(f"  id={message.id}")
    print(f"  created_at={message.created_at.isoformat()}")
    print(f"  text={message.text}")
    # TODO: add more parameters

Using as a command-line tool

Scrape one or many channels and save all messages to messages.csv:

tchan messages.csv channel1 [channel2 ... channelN]

Tests

To run all tests, execute:

make test  # or just `pytest`

Make sure to install development requirements.

Tests were made on a channel created for this task: tchantest.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tchan-0.1.4.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

tchan-0.1.4-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file tchan-0.1.4.tar.gz.

File metadata

  • Download URL: tchan-0.1.4.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for tchan-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e3c382fca3fa1898ae78b025b8aa6dfea81a75df71d394d9ae1655baf535e321
MD5 b165e5c63f8d7d28a8be634bc2835c23
BLAKE2b-256 5d53ceda0c6b07080029ca3cc8b2bc15b1e9ceef7654789e6b2c610013edbc64

See more details on using hashes here.

File details

Details for the file tchan-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: tchan-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for tchan-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 20d267056e7b820c8a7b070ea25dd5dee3255d9512c0e646e69f6d93d8f9e7c8
MD5 d54e31096e747db4dab866321ebe2df7
BLAKE2b-256 f7608ead009daa258388e92ac3276095ef33073a3dc36c7a414afecc35c5b464

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page