simple_html_dom(3)

How to traverse the DOM tree?

// If you are not so familiar with HTML DOM, check this link to learn more...

// Example
echo $html->find("#div1", 0)->children(1)->children(1)->children(2)->id;
// or 
echo $html->getElementById("div1")->childNodes(1)->childNodes(1)->childNodes(2)->getAttribute(‘id‘);

You can also call methods with Camel naming convertions.

Method Description

mixed

$e->children ( [int $index] )

Returns the Nth child object if index is set, otherwise return an array of children.

element

$e->parent ()

Returns the parent of element.

element

$e->first_child ()

Returns the first child of element, or null if not found.

element

$e->last_child ()

Returns the last child of element, or null if not found.

element

$e->next_sibling ()

Returns the next sibling of element, or null if not found.

element

$e->prev_sibling ()

Returns the previous sibling of element, or null if not found.
时间: 2024-08-24 12:43:30

simple_html_dom(3)的相关文章

simple_html_dom配合snoopy使用

https://github.com/samacs/simple_html_dom Snoopy的特点是“大”和“全”,一个fetch什么都采到了,可以作为采集的第一步.接下来就需要用simple_html_dom来细细的把想要的部分,扣出来.当然,如果你特别特别擅长正则,而且又钟爱正则,你也可以用正则去匹配抓取. simple_html_dom其实是一个dom解析的过程.php内部也提供了一些解析的方法,但是这个simple_html_dom可以说做得比较专业,一个类,满足了很多你想要的功能.

php利用simple_html_dom类,获取页面内容,充当爬虫角色

PHP脚本扮演爬虫的角色,可能大家第一时间想到可能会是会正则,个人对正则的规则老是记不住,表示比较难下手,今天工作中有个需求需要爬取某个网站上的一些门店信息 无意间在网上看到一个比较好的类库叫:simple_html_dom github下载地址:https://github.com/samacs/simple_html_dom 最重要的一步:你得先了解别人网站的结构,知道从哪个tab开始是你想要的数据 下面演示下过程吧 实现过程我分了三步 1.将门店信息的经纬度,名称等一些重要信息先插入本地表

php解析html类库simple_html_dom

下载地址:https://github.com/samacs/simple_html_dom 一直以来使用php解析html文档树都是一个难题.Simple HTML DOM parser 帮我们很好地解决了这个问题.可以通过这个php类来解析html文档,对其中的html元素进行操作 (PHP5+以上版本). 解析器不仅仅只是帮助我们验证html文档:更能解析不符合W3C标准的html文档.它使用了类似jQuery的元素选择器,通过元素的id,class,tag等等来查找定位:同时还提供添加.

黄聪:PHP使用Simple_HTML_DOM遍历、过滤及保留指定属性

<? /* * 参考资料: * http://www.phpddt.com/manual/simplehtmldom_1_5/manual_api.htm * http://www.phpddt.com/manual/simplehtmldom_1_5/manual.htm*/ class HtmlUtil{ /* * $allow:只允许这些属性存在 * $exceptions:一些特殊的元素,可以存在某些属性 */ public function clear_child_html_attri

PHP CURL抓取网页 simple_html_dom类

抓取网页数据后 数据录入到discuz中 <?php include('simple_html_dom.php'); function urlText(){ $url = 'http://www.kxt.com/data/3.html';//外汇 $ch=curl_init(); $timeout = 1; // echo CURLOPT_URL; // CURLOPT_URL: 这是你想用PHP取回的URL地址.你也可以在用curl_init()函数初始化时设置这个选项 curl_setopt

simple_html_dom使用小结

simple_html_dom使用小结 分类: PHP2012-08-31 14:24 3094人阅读 评论(0) 收藏 举报 htmlcallbackstringdivfunctionfile 1.文件夹结构如下: php解析html页面工具 simple html dom 使用的简单介绍: (1)下载( http://sourceforge.net/projects/simplehtmldom/files/) : (2)解压,manual目录是使用文档(很容易看懂的,也可以看这里http:/

simple_html_dom(1)

// 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)        ech

PHP爬虫抓取网页内容 (simple_html_dom.php)

使用simple_html_dom.php,下载|文档 因为抓取的只是一个网页,所以比较简单,整个网站的下次再研究,可能用Python来做爬虫会好些. 1 <meta http-equiv="content-type" content="text/html;charset=utf-8"/> 2 <?php 3 include_once 'simplehtmldom/simple_html_dom.php'; 4 //获取html数据转化为对象 5

php simple_html_dom 一个iconv错误引起解析中断的问题,貌似内存溢出

环境: $pageNum = 8; for ($i = 1; $i < $pageNum; $i++) { $html = new simple_html_dom(); $host = 'http://xxxxxx'; $url = sprintf ($this->urlFormat, $i); $html->load_file($url); echo "<br>" . $i . "start1 ".$url."<br&

黄聪:simple_html_dom 换行符丢失

我在利用simple_html_dom来解析文档是,想要将其中的换行符替换成<BR> , 结果试了好几次没有成功,但是在原始文档中确实是有换行符的.后来索性把装载进来的文档打印出来,结果发现,装载进来以后换行符0x0a就没有了. 于是我跑到simple_html_dom的源码中去看到底怎么回事,原来在调用file_get_html, 后面有一排的缺省参数,其中有一个stripRN,缺省是打开的,也就是说缺省情况下,换行符会被删除,所以装载进来的文档就找不到换行符了.只要把这个参数改为false