To implement a simple Laravel API endpoint that scrapes the USDT/EGP price from a public converter page (like the "AJELLY123" approach you referenced), follow these steps. This guide uses Laravel’s controller structure and the Symfony DomCrawler/HttpClient libraries, which are well-suited for scraping static HTML content[1][8].
Step-by-Step Implementation in Laravel
1. Install Laravel and Required Packages
If you haven’t already, create a new Laravel project:
composer create-project laravel/laravel usdt-egp-scraper
Install the necessary scraping libraries:
composer require symfony/dom-crawler symfony/http-client
2. Create a Scraping Controller
Generate a controller:
php artisan make:controller UsdtScraperController
3. Implement the Scraping Logic
Edit app/Http/Controllers/UsdtScraperController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\DomCrawler\Crawler;
class UsdtScraperController extends Controller
{
public function getUsdtEgp(): JsonResponse
{
// Target the Coinbase converter page
$url = 'https://www.coinbase.com/converter/usdt/egp';
// Fetch the page content
$client = HttpClient::create();
$response = $client->request('GET', $url);
$html = $response->getContent();
// Parse the HTML
$crawler = new Crawler($html);
// Inspect the page to find the correct selector for the price
// This selector may change; update as needed
$priceNode = $crawler->filter('h1')->first();
$priceText = $priceNode->text();
// Extract the numeric value (e.g., "1 USDT = 50.60 EGP")
preg_match('/= ([\d.]+) EGP/', $priceText, $matches);
$price = $matches[1] ?? null;
return response()->json([
'usdt_egp' => $price,
'source' => $url,
]);
}
}
Note: You may need to adjust the CSS selector (h1) based on the actual structure of the Coinbase converter page. Use browser dev tools to inspect the element containing the price.
4. Add a Route
In routes/api.php, add:
use App\Http\Controllers\UsdtScraperController;
Route::get('/usdt-egp', [UsdtScraperController::class, 'getUsdtEgp']);
5. Test the Endpoint
Start your Laravel server: