php simple_html_dom html 解析

贴上链接

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]');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值