类jquery的php解析html dom库,simple_html_dom

simple html dom 是使用PHP实现的一个类似于jquery的类库。在分析捉取下来的网页时,非常有有。

项目官方网站:http://simplehtmldom.sourceforge.net/

手册地址:http://simplehtmldom.sourceforge.net/manual.htm


PHP Simple HTML DOM Parser

Description, Requirement & Features

  • A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
  • Require PHP 5+.
  • Supports invalid HTML.
  • Find tags on an HTML page with selectors just like jQuery.
  • Extract contents from HTML in a single line.

Download & Documents

  • Download latest version form Sourceforge.
  • Read Online Document.

Quick Start

  • How to get HTML elements?
  • How to modify HTML elements?
  • Extract contents from HTML
  • Scraping Slashdot!
// Create DOM from URL or file
$html =  file_get_html( 'http://www.google.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>';

Feedback

  • Feature Request Tracker
  • Bug Tracking System
  • Discussion Forums
  • Contact Author

Author: S.C. Chen ([email protected])
Original idea is from Jose Solorzano's  HTML Parser for PHP 4. 
Contributions by: Yousuke Kumakura (Attribute Filters)

你可能感兴趣的:(PHP,simple_html_dom)