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