innmind / html
Library to abstract html manipulation
Installs: 8 067
Dependents: 5
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Language:HTML
pkg:composer/innmind/html
Requires
- php: ~8.2
- innmind/filesystem: ~8.1
- innmind/immutable: ~5.16
- innmind/url: ~4.0
- innmind/validation: ~2.0
- innmind/xml: ~8.0
- symfony/dom-crawler: >=6.3 <7.0.7
Requires (Dev)
- innmind/black-box: ^6.4.1
- innmind/coding-standard: ~2.0
- innmind/static-analysis: ^1.2.1
README
This library is an extension of innmind/xml to support working properly with html as a node tree.
Important: you must use vimeo/psalm to make sure you use this library correctly.
Installation
composer require innmind/html
Usage
use Innmind\Html\{ Reader, Document, }; use Innmind\Xml\{ Node, Element, Element\Custom, }; use Innmind\Filesystem\File\Content; use Innmind\Immutable\Maybe; $read = Reader::new(); $html = $read( Content::ofString(\file_get_contents('https://github.com/')), ); // Maybe<Document|Element|Custom|Node>
Extract some elements of the tree
This library provides some visitors to extract elements out of the dom tree, the example below show you how to extract all the h1 elements of a tree:
use Innmind\Html\Visitor\Elements; $h1s = Elements::of('h1')($html);
Here $h1s is a sequence of Element which are all h1 elements.
Here's the full list of visitors you have access to: