Skip to content

Scrape Telegram public channels (Python library + CLI)

License

Notifications You must be signed in to change notification settings

PythonicCafe/tchan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Scrape Telegram public channels (Python library + CLI)

Resources

License

Stars

Watchers

Forks

Packages

No packages published