Examples
Every example is a small Composer project in examples/ of the repository. It scrapes fixture pages served by PHP's built-in web server (php -S) on 127.0.0.1, so it needs no internet and gives the same output every time. The pages on this site include the code straight from those files.
| Example | What it shows |
|---|---|
| Open Graph article | Every meta tag and Open Graph field of a news article, OgDomParser and OgParser side by side |
| JSON-LD @graph | A Yoast-style @graph with @id references; how the parser order decides which value wins |
| Twitter card parser | A custom ParserInterface that reads twitter:* tags as a fallback |
| Broken pages | Reversed attributes, unquoted tags, invalid JSON-LD, UTF-8 without a declaration, Windows-1250, an empty page |
| Fetch errors | 404, 500, timeout, redirect loop, refused connection, http_errors and allow_redirects |
| Link preview (SSRF-safe) | Preview cards for user-submitted URLs: URL guard, pinned DNS, checked redirects, escaped output |
| Testing with a mock | Unit-testing code that calls parseUrl() with a Guzzle MockHandler |
How they are tested
Each example has:
composer.jsonrequiringtomaj/meta-scraper,run.php, the example itself, which prints what it found,site/with the fixture pages (and arouter.phpwhere a page needs a special status, header or delay),e2e.sh, which startsphp -Sforsite/, runsrun.phpand compares its output withexpected-output.txt.
The Examples workflow runs every e2e.sh on every push and pull request. examples/ci/use-local-meta-scraper.sh installs the package from the checkout through a Composer path repository, so the examples always run against the code of the pull request, not a released version. When a change to the library changes an example's output, the workflow fails and shows the difference.
Run one yourself
git clone https://github.com/tomaj/meta-scraper.git
cd meta-scraper
examples/ci/recipe.sh link-previewrecipe.sh copies the example to a temporary directory, installs it against your checkout and runs its e2e.sh. It needs PHP 8.4+, Composer and free ports 8401 to 8406.