zoukankan      html  css  js  c++  java
  • php simple_html_dom

        这个真的很好用,如果用正则,就太麻烦了。

        首先,下载simple_html_dom,用include_once就可以使用了。

        可以直接定位,可以像个对象一样操作,很方便。

         $ret=file_get_html('url');//获得解析的文档

         find();//函数可以定位标签

         比如: $ret->find('div');//定位div标签

                 $ret->find('a',1);//定位a标签的第二个元素,返回的是个数组

                 $ret->find(' div a');//定位div 标签里的a元素

                 $ret->find('div.content');//定位含有<div class='content'>的块

                 $ret->find('div[id=content]');//定位含有<div id='content'>的块

                 $ret->find('#id');//定位含有id的标签

        $ret可以遍历元素:

                  $ret->parent();

                  $ret->children();

                  $ret->pre_sibling();

                  $ret->next_sibling();

        可以访问标签内容:

                 $ret->innertext;

                 $ret->outertext;

                 $ret->tag;

        可以像对象一样访问元素:

                $ret->href;

    很强大,用这个解析html很容易和方便,带来特别的简单美。

         

       

  • 相关阅读:
    【整理】Linux 下 自己使用的 debug宏 printf
    STM32学习笔记:创建标准库工程模板
    【闲谈】第一份实习(下)
    Ceres-Solver库入门
    ceres-solver库使用示例
    ceres-solver库编译说明
    October 23, 2013
    Pollution over East China : Image of the Day
    谈谈PCI的GXL
    InfoQ访谈:Webkit和HTML5的现状和趋势
  • 原文地址:https://www.cnblogs.com/xshang/p/3440332.html
Copyright © 2011-2022 走看看