Home >Backend Development >PHP Tutorial >使用DOMDocument抓取数据 并分类
http://smart-phones.biyixia.com/node/1013
<?php/** * Created by PhpStorm. * User: Admin * Date: 13-11-14 * Time: 下午10:42 */$link[]=array();$page_url='http://smart-phones.biyixia.com/node/1013';//$content=get_data($page_url);$doc= new DOMDocument();@$doc->loadHTMLFile($page_url);$div_contents = $doc->getElementsByTagName('div');print_r($div_contents);foreach($div_contents as $div_content ){ $items = $div_content->getAttribute("class"); $itme_value = $items->nodeValue;}echo $items_value;
$link[]=array();$page_url='http://smart-phones.biyixia.com/node/1013';//$content=get_data($page_url);$doc= new DOMDocument();@$doc->loadHTMLFile($page_url);$xPath = new DOMXPath($doc);$div_tags = $xPath->evaluate("/html/body//div//@class");for($i=0;$i<$div_tags->length;$i++){ $div_tag=$div_tags->item($i); $div_contents=$div_tag->nodeValue; echo $div_contents; echo "<br>";}
<div class="col-xs-3 key">图像尺寸</div>
你都会xpath,还要问么?
自己用firebug或类似插件查一查就知道xpath了