ElephScraper is a lightweight and PHP-native web scraping toolkit built using Guzzle and Symfony DomCrawler. It provides a clean and powerful interface to extract HTML content, metadata, and structured data from any website.
Fast. Clean. Eleph-style scraping. ๐โก
- โ Extract metadata: title, description, keywords, author, charset, canonical, and more
- โ Supports Open Graph, Twitter Card, CSRF tokens, and HTTP-equiv headers
- โ Extract headings, paragraphs, images, lists, and links
- โ
Powerful
filter()method with support for class/ID/tag-based selectors - โ Return raw HTML or clean plain text
- โ Clean return types: string, array, or associative array
- โ Built with Guzzle + Symfony DomCrawler + CssSelector
Install via Composer:
composer require riodevnet/elephscraperRequires PHP 7.4 or newer.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Riodevnet\Elephscraper\ElephScraper;
$scraper = new ElephScraper("https://example.com");
echo $scraper->title(); // "Welcome to Example.com"
echo $scraper->description(); // "Example site for testing"
print_r($scraper->h1()); // ["Main Title", "News"]
print_r($scraper->openGraph());$scraper->title();
$scraper->description();
$scraper->keywords();
$scraper->keywordString();
$scraper->charset();
$scraper->canonical();
$scraper->contentType();
$scraper->author();
$scraper->csrfToken();
$scraper->image();$scraper->openGraph(); // All OG meta
$scraper->openGraph("og:title"); // Specific OG tag
$scraper->twitterCard(); // All Twitter tags
$scraper->twitterCard("twitter:title");$scraper->h1();
$scraper->h2();
$scraper->h3();
$scraper->h4();
$scraper->h5();
$scraper->h6();
$scraper->p();$scraper->ul(); // all <ul><li> text
$scraper->ol(); // all <ol><li> text$scraper->images(); // just src URLs
$scraper->imageDetails(); // src, alt, title$scraper->links(); // just hrefs
$scraper->linkDetails(); // full detail$scraper->filter(
element: 'div',
attributes: ['id' => 'main'],
multiple: false,
extract: ['.title', '#desc', 'p'],
returnHtml: false
);$scraper->filter(
element: 'div',
attributes: ['class' => 'card'],
multiple: true,
extract: ['h2', '.subtitle', '#info'],
returnHtml: false
);$scraper->filter(
element: 'section',
attributes: ['class' => 'hero'],
returnHtml: true
);Extract selectors support:
- Tag names:
h1,p,span, etc.- Class:
.className- ID:
#idNameOutput keys auto-normalized to original selector.
Found a bug? Want to add features? Open an issue or create a pull request!
MIT License ยฉ 2025 โ ElephScraper
ElephScraper is your dependable PHP elephant โ strong, smart, and always ready to extract the right data.