Use DOMDocument to capture and classify data

Source: Internet
Author: User
Capture and classify data using DOMDocument: http://smart-phones.biyixia.com/node/1013&lt ;? Php/** & nbsp; * & nbsp; Created & nbsp; by & nbsp; PhpStorm. & nbsp; * & nbsp; User: & nbsp; Admin & nbs use DOMDocument to capture and classify data
Http://smart-phones.biyixia.com/node/1013

 /**
* Created by PhpStorm.
* User: Admin
* Date: 13-11-14
* Time: PM
*/
$ 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;


What I want is: Cell phone size => XXXX
Product Price => XXXX

Sorry for your guidance !!! Share:
------ Solution --------------------
You all use xpath. do you want to ask?
You can use firebug or similar plug-ins to check the xpath.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.