php dom操作

在net.tutsplus.com看到篇文章觉得不错就记录下来,可以方便以后抓取网页内容然后进行过滤操作!

http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/

    # get the first occurrence of id="foo"  
    $single = $html->find('#foo', 0);   
      
    # get all elements with class="foo"  
    $collection = $html->find('.foo');   
      
    # get all the anchor tags on a page   
    $collection = $html->find('a');   
      
    # get all anchor tags that are inside H1 tags   
    $collection = $html->find('h1 a');   
      
    # get all img tags with a title of 'himom'  
    $collection = $html->find('img[title=himom]');

另外还发现一个跟方便的类库 QueryPath http://querypath.org/
这个可以称得上是PHP版本的jquery dom操作,具体例子可以看官方网站

还有一个 http://code.google.com/p/phpquery/ 也是和jquery一样的php版本的dom操作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值