Search by

tomaj / meta-scraper

tomaj

Extracts title, description, Open Graph and schema.org JSON-LD metadata from HTML pages.

4.3.0 2020-11-23 09:05 UTC

This package is auto-updated.

Last update: 2026-11-26 06:48:37 UTC


README

Meta Scraper

Extracts title, description, Open Graph and schema.org JSON-LD metadata from HTML pages.

Documentation: https://tomaj.github.io/meta-scraper/

Getting started · Parsers · Examples · API reference · Changelog

Latest Stable Version CI Coverage Status PHPStan OpenSSF Scorecard Documentation License PHP Version

What is meta-scraper?

meta-scraper reads the metadata a web page publishes about itself and returns it as one Meta object:

  • the <title> and the description, keywords and author meta tags,
  • Open Graph properties (og:title, og:description, og:type, og:url, og:site_name, og:image, article:section, article:published_time, article:modified_time),
  • schema.org JSON-LD (<script type="application/ld+json">): headline, description, authors, sections, tags, image, URL and dates.

Each source has its own parser. Combine them and the first parser that finds a value wins.

Installation

Requires PHP 8.4 or newer.

composer require tomaj/meta-scraper

Usage

use Tomaj\Scraper\Parser\OgParser;
use Tomaj\Scraper\Parser\SchemaParser;
use Tomaj\Scraper\Scraper;

$scraper = new Scraper();

// parse HTML you already have
$meta = $scraper->parse($html, [new SchemaParser(), new OgParser()]);

// or download the page with Guzzle and parse it
$meta = $scraper->parseUrl($url, [new SchemaParser(), new OgParser()]);

echo $meta->getTitle();
echo $meta->getOgImage();
foreach ($meta->getAuthors() as $author) {
    echo $author->name();
}

Parsers, fetching options (timeouts, User-Agent, your own Guzzle client), error handling and the full API are described in the documentation.

Contributing

Contributions are welcome. See CONTRIBUTING.md and the Code of Conduct.

Security

Do not report security vulnerabilities in public issues. See SECURITY.md; it also explains why parseUrl() must not receive untrusted URLs without SSRF protection.

License

MIT. See LICENSE.md.