windstep/htmldom

适用于 Laravel 4 的简单 Html Dom 解析器

2.0.0 2021-04-01 13:58 UTC

This package is auto-updated.

Last update: 2024-08-29 06:18:08 UTC


README

基于 Simple HTML Dom 解析器的 Laravel 4 和 5 的 Htmldom 包

安装

将以下行添加到 composer.jsonrequire 部分

{
    "require": {
        "yangqi/htmldom": "1.0.*"
    }
}

Laravel 5 设置(与 Laravel 4 相同)

  1. 将服务提供者添加到 config/app.php
'providers' => array(
    ...
	'Yangqi\Htmldom\HtmldomServiceProvider',
    ...
  1. 将别名添加到 config/app.php
'aliases' => array(	
    ...
	'Htmldom' => 'Yangqi\Htmldom\Htmldom',
    ...

用法

  1. 使用以下命令
$html = new \Htmldom('http://www.example.com');

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';

查看详细文档 http://simplehtmldom.sourceforge.net/manual.htm