Home > Backend Development > PHP Tutorial > 使用DOMDocument抓取数据 并归类

使用DOMDocument抓取数据 并归类

WBOY
Release: 2016-06-13 12:32:59
Original
920 people have browsed it

使用DOMDocument抓取数据 并分类
http://smart-phones.biyixia.com/node/1013

<?php<br />
/**<br />
 * Created by PhpStorm.<br />
 * User: Admin<br />
 * Date: 13-11-14<br />
 * Time: 下午10:42<br />
 */<br />
$link[]=array();<br />
<br />
$page_url='http://smart-phones.biyixia.com/node/1013';<br />
//$content=get_data($page_url);<br />
$doc= new DOMDocument();<br />
@$doc->loadHTMLFile($page_url);<br />
<br />
$div_contents = $doc->getElementsByTagName('div');<br />
<br />
print_r($div_contents);<br />
foreach($div_contents as $div_content ){<br />
    $items = $div_content->getAttribute("class");<br />
    $itme_value = $items->nodeValue;<br />
}<br />
echo $items_value;
Copy after login


我想要的效果是 比如: 手机尺寸=>XXXX
                  产品价格=>XXXX

跪求指导!!!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template