f" />
入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

php simple_html_dom html 解析

创建时间:2015-01-23 投稿人: 浏览次数:642

贴上链接

http://www.ecartchina.com/php-simple-html-dom/manual.htm



//使用url和file都可以创建DOM
$html = file_get_html("http://www.google.com/");

//找到所有图片
foreach($html->find("img") as $element)
       echo $element->src . "<br>";

//找到所有链接
foreach($html->find("a") as $element)
       echo $element->href . "<br>";



// Find all anchors, returns a array of element objects 找到所有的a标签,返回一个 数组元素对象
$ret = $html->find("a");

// Find (N)th anchor, returns element object or null if not found (zero based)  找到第n个开始的a标签 , 返回数组 或者 null(如果没有找到的)
$ret = $html->find("a", 0);

// Find lastest anchor, returns element object or null if not found (zero based)  
$ret = $html->find("a", -1);

// Find all <div> with the id attribute 
$ret = $html->find("div[id]");

// Find all <div> which attribute id=foo
$ret = $html->find("div[id=foo]");



// 查找所有id=foo的元素
$ret = $html->find("#foo");

// 查找所有class=foo的元素
$ret = $html->find(".foo");

// 查找所有拥有 id属性的元素
$ret = $html->find("*[id]");

// 查找所有 anchorsimages标记
$ret = $html->find("a, img");

// 查找所有有"title"属性的anchors and images
$ret = $html->find("a[title], img[title]");

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。