larammerce/html-dom

针对 Laravel 8 的简单 Html Dom 解析器

v1.1.1 2022-01-13 22:32 UTC

This package is auto-updated.

Last update: 2024-09-14 04:11:22 UTC


README

基于 Simple HTML Dom Parser 的 Laravel 8 HtmlDom 包

安装

将以下行添加到 composer.json 文件的 require 部分:

{
  "require": {
    "larammerce/html-dom": "1.1.*"
  }
}

Laravel 8 设置

  1. 将服务提供者添加到 config/app.php
'providers' => array(
    ...
	'Larammerce\HtmlDom\HtmlDomServiceProvider',
    ...
  1. 将别名添加到 config/app.php
'aliases' => array(	
    ...
	'HtmlDom' => 'Larammerce\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