h0gar / xpath
0.1.4
2016-01-04 13:47 UTC
This package is not auto-updated.
Last update: 2024-09-14 14:50:57 UTC
README
#Xpath
一个轻量级的xpath操作包。
composer require h0gar/xpath *
HTML
$html = file_get_contents('page.html');
$doc = new \H0gar\Xpath\Doc($html, 'html');
XML
$xml = file_get_contents('page.xml');
$doc = new \H0gar\Xpath\Doc($xml, 'xml');
$item = $doc->item('/html/body/div[1]/div/div[2]/ul/li[0]');
#or
$item = $doc->item('/html/body/div[1]')->item('div/div[2]/ul/li', 1);
$items = $doc->items('/html/body/div[1]/div/div[2]/ul/li');
foreach($items as $item)
//...
$next = $item->next();
$prev = $item->prev();
$parent = $item->parent();
$html = $item->html();
#or
$html = $doc->html('/html/body/div[1]/div/div[2]/ul/li[0]');
#or
$html = $doc->html('/html/body/div[1]/div/div[2]/ul/li', 1);
$text = $item->text();
#or
$text = $doc->text('/html/body/div[1]/div/div[2]/ul/li[0]');
#or
$text = $doc->text('/html/body/div[1]/div/div[2]/ul/li', 1);
$href = $item->attr('href');
$domelement = $item->getNode();
$domxpath = $item->getXpath();
##贡献
请将所有问题和pull请求提交到h0gar/xpath仓库。
##许可证
开源软件,采用MIT许可证