定制 gaswelder/htmlparser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gaswelder/htmlparser

Composer 安装命令:

composer require gaswelder/htmlparser

包简介

HTML parser and DOM implementation

README 文档

README

This is an HTML parser with a minimal DOM implementation. It doesn't depend on PHP's bundled libxml and DOM and handles some of the broken markup encountered in the wild.

Usage example

<?php
use \gaswelder\htmlparser\Parser;
use \gaswelder\htmlparser\ParsingException;

try {
	$doc = Parser::parse($html);
} catch(ParsingException $e) {
	// ...
	return;
}

$images = $doc->querySelectorAll('#posts .post img');
foreach ($images as $img) {
	$src = $img->getAttribute('src');
	echo $src, "\n";
}

Features

All container nodes (DocumentNode and ElementNode) have the querySelector and querySelectorAll methods which support a limited subset of CSS2:

  • type selectors (like div)
  • some attribute selectors ([checked], [attr="val"], [attr$="val"], [attr^="val"])
  • class selectors (.active)
  • ID selectors (#main)

Also they support these combinators:

  • descendant (ul li)
  • child (ul > li)
  • sibling (li + li)

The nodes can be printed to the console, and the output will be similar to Firefox's console:

<?php
$list = $doc->getElementsByTagName('a');
echo $list, PHP_EOL;

might produce this output:

NodeList [ <a>, <a#top>, <a.first>, <a>, <a> ]

Installation

Composer dudes do this in the console:

composer require gaswelder/htmlparser

Old-school dudes (if still alive) may download the library to whatever $libdir they have and do this:

require "$libdir/htmlparser/init.php";

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固