php dom操作

来源:互联网 发布:mac英文字体打包下载 编辑:程序博客网 时间:2024/05/21 14:56

在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操作
原创粉丝点击