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