跳转到主要内容

抓取Telegram公共频道(Python库+命令行界面)

项目描述

tchan - Telegram频道爬虫

Python库和命令行界面用于爬取Telegram公共频道。由于这个爬虫使用Telegram频道网页预览,它不会工作

  • 启用“限制保存内容”选项的公共频道
  • 私人频道
  • 公共群组
  • 私人群组

由于评论是在群组中制作的,因此也无法检索评论。

安装

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

作为库使用

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

作为命令行工具使用

抓取一个或多个频道,并将所有消息保存到messages.csv

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

测试

要运行所有测试,请执行

make test  # or just `pytest`

请确保安装开发需求。

测试是在为此任务创建的频道上进行的:tchantest

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

tchan-0.1.4.tar.gz (8.8 kB 查看哈希值)

上传时间 源代码

构建分发

tchan-0.1.4-py3-none-any.whl (9.1 kB 查看哈希值)

上传时间 Python 3

支持者