PHP code example of ymsoft / telegram-channel-scrapper
1. Go to this page and download the library: Download ymsoft/telegram-channel-scrapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ymsoft / telegram-channel-scrapper example snippets
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.
/**
* @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
use Ymsoft\TelegramChannelScrapper\TelegramCS;
$service = new TelegramCS('channel_name');
/** @var \Ymsoft\TelegramChannelScrapper\Entity\Message\Message $message */
$message = $service->getMessageById(1);
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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.