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 hashes)
Built Distribution
tchan-0.1.4-py3-none-any.whl
(9.1 kB
view hashes)