ytekeli/dom-selector

An HTML DOM selector and extractor with using YAML config.

v0.2.0 2021-06-26 21:33 UTC

This package is auto-updated.

Last update: 2024-04-27 03:45:43 UTC


README

Latest Version Build Status Code Coverage Scrutinizer Code Quality Software License

An HTML DOM selector and extractor with using YAML config.

  • Free software: MIT license

Requirements

  • PHP ^7.3 | ^8.0
  • ext-yaml

Install

Install the latest version using composer.

$ composer require ytekeli/dom-selector

This package can be found on packagist and is best loaded using composer. We support php 7.3, 7.4 and 8.0.

Example

You can find many examples of how to use the DOM Selector in the tests directory.

// Assuming you installed from Composer:
require "vendor/autoload.php";

use DOMSelector\DOMSelector;

$yaml_string = '
title:
    css: "h1"
    type: Text
link:
    css: "h2 a"
    type: Link';

$selector = DOMSelector::fromYamlString($yaml_string);
$extracted = $selector->extract('<h1>Title</h1><h2>Usage <a class="headerlink" href="https://example.com">¶</a></h2>');

print_r($extracted);
// output

Array
(
    [title] => Title
    [link] => https://example.com
)

We strongly inspired by selectorlib written with python.