innmind / html
抽象HTML操作的库
6.4.0
2024-06-26 08:51 UTC
Requires
- php: ~8.2
- innmind/filesystem: ~7.1
- innmind/url: ~4.0
- innmind/xml: ~7.7
- symfony/dom-crawler: >=6.3 <7.0.7
Requires (Dev)
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~9.0
- vimeo/psalm: ~4.22
README
这个库是 innmind/xml
的扩展,以支持将HTML作为节点树正确工作。
重要:您必须使用 vimeo/psalm
来确保正确使用此库。
安装
composer require innmind/html
用法
use Innmind\Html\Reader\Reader; use Innmind\Xml\Node; use Innmind\Filesystem\File\Content; use Innmind\Immutable\Maybe; $read = Reader::default(); $html = $read( Content::ofString(\file_get_contents('https://github.com/')), ); // Maybe<Node>
提取树的一些元素
此库提供了一些访问者来从DOM树中提取元素,以下示例展示了如何提取所有 h1
元素
use Innmind\Html\Visitor\Elements; $h1s = Elements::of('h1')($html);
在这里 $h1s
是一组 Element
,它们都是 h1
元素。
以下是您可访问的完整访问者列表