Ganon Crawl Web Page Example

Source: Internet
Author: User

Project Address: http://code.google.com/p/ganon/
Document: Http://code.google.com/p/ganon/w/list

This is a powerful feature that uses a JS-like tag Selector to identify the DOM

The Ganon library gives access to html/xml documents in a very simple object oriented the. It eases modifying the DOM and makes finding elements easy with css3-like queries.

Ganon Use Example:

// Parse The Google Code website into a DOM $html = file_get_dom (' http://code.google.com/');

Access
Accessing elements is made easy through the Css3-like selectors and the object model.

//Find all the paragraph tags with a class attribute and print the//value of the class attribute foreach($html(' P[class] ') as $element) {   Echo $element-class, "<br>\n"; }  //Find the first div with ID "Gc-header" and print the plain text of//The parent element (plain text means no HTML ta GS, just the text) Echo $html(' Div#gc-header ', 0)->parent->Getplaintext (); //Find out how many tags there is which is "ns:tag" or "div", but not//"a" and does not have a class attribute Echo Count($html(' (Ns|tag, div +!a) [!class] ');?>

Modification
Elements can easily modified after you ' ve found them.

//Find All paragraph tags which is nested inside a div tag, change//their ID attribute and print the new HTML Co De     foreach($html(' Div p ') as $index=$element) {       $element->id = "id$index"; }     Echo $html; //Center all links inside a document which start with "HTTP +/"//and print out the new HTML     foreach($html(' A[href ^= '/'/'] ') as $element) {       $element->wrap (' Center '); }     Echo $html; //Find all odd indexed "TD" elements and change the HTML to make them links     foreach($html(' Table td:odd ') as $element) {       $element->setinnertext (' <a href= ' # ' > '.$element->getplaintext (). ' </a> '); }     Echo $html;

Beautify
Ganon can also help you beautify your code and format it properly.

// beautify the old HTML code and print out the new, formatted code     Dom_format ($htmlarray(' attributes_case ' = case_lower));      Echo $html;

Ganon Crawl Web Page Example

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.