ymsoft / telegram-channel-scrapper
Public telegram channel scrapper.
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/collections: ^10.32
- psr/http-client: ^1.0
- symfony/css-selector: ^6.3
- symfony/dom-crawler: ^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.38
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2025-04-20 13:08:00 UTC
README
Public telegram channels scrapper
This package is intended for those who need to efficiently scrape a public telegram channel. This is done quite easily:
use Ymsoft\TelegramChannelScrapper\TelegramCS; $scrapper = new TelegramCS('channel_name'); /** @var \Ymsoft\TelegramChannelScrapper\Entity\Channel $channel */ $channel = $scrapper->getChannel(); /** * By default, you will scrap the latest 20 messages. * @var \Illuminate\Support\Collection<\Ymsoft\TelegramChannelScrapper\Entity\Message\Message> $messages */ $messages = $scrapper->getMessages(); $messages->count(); // will return 20 // In order to download 20 more messages you need $scrapper->loadPrevMessages(); $scrapper->getMessages()->count() // will return 40 // You can download old messages endlessly until you download everything.
Since this package uses illuminate/collections you can use all the methods described here to work with a collection of messages.
/** * @var \Illuminate\Support\Collection<\Ymsoft\TelegramChannelScrapper\Entity\Message\Message> $messages */ $messages = $service->getMessage(); $messages->all(); $messages->count(); $messages->toArray(); $messages->firstWhere('id', 1); $messages->last(); $messages->first(); // and much more https://laravel.com/docs/10.x/collections#available-methods
Channel
View all entity attributes Channel.
Message
View all entity attributes Message.
Installation
You can install the package via composer:
composer require ymsoft/telegram-channel-scrapper
Advanced usage
Scrap special message by concrete id
If you know the message ID you can get it:
use Ymsoft\TelegramChannelScrapper\TelegramCS; $service = new TelegramCS('channel_name'); /** @var \Ymsoft\TelegramChannelScrapper\Entity\Message\Message $message */ $message = $service->getMessageById(1);
Http client (CUSTOM HEADERS & PROXY)
If you want to add your own headers or make requests through a proxy, you can pass your http client instance as the second parameter:
use Ymsoft\TelegramChannelScrapper\TelegramCS; /* * You can provide any http client that implements psr/http-client * Psr\Http\Client */ $client = new \GuzzleHttp\Client([ 'headers' => [ 'Accept-Language' => 'en-US,en;q=0.9', 'Accept' => 'text/html', ], 'proxy' => 'http://localhost:8125', ]); $service = new TelegramCS('channel_name', $client);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Thank you for considering contributing to the TelegramCS Package!
License
The MIT License (MIT). Please see License File for more information.