Git Product home page Git Product logo

ocgumbo's Introduction

OCGumbo - An Objective-C HTML5 parser.

OCGumbo is an Objective-C wrapper of the Google Gumbo.

Basic Usage

  1. Add Gumbo sources or lib to your project.
  2. Add OCGumbo file and import "OCGumbo.h", then use OCGumboDocument to parse an html string.

####Objects####

ClassDescription
OCGumboDocumentthe root of a document tree
OCGumboElementan element in an HTML document
OCGumboTextthe textual content of an element
OCGumboNode a single node in the document tree
OCGumboAttributean attribute of an Element object

####Examples####

OCGumboDocument *document = [[OCGumboDocument alloc] initWithHTMLString:htmlString];
OCGumboElement *root = document.rootElement;
//document: do something with the document.
//rootElement: do something with the html tree.

Extension

Now, OCGumbo add more Query support, add "OCGumbo+Query.h" and enjoy it.

####Query APIs####

MethodDescription
.Query( )Query children elements from current node by selector
.text( )Get the combined text contents of current object
.html( )Get the raw contents of current element
.attr( )Get the attribute value of the element by attributeName
.find( )Find elements that match the selector in the current collection
.children( )Get immediate children of each element in the current collection matching the selector
.parent( )Get immediate parents of each element in the collection matching the selector
.parents( )Get all ancestors of each element in the collection matching the selector
.first( )Get the first element of the current collection
.last( )Get the last element of the current collection
.get ( )Get the element by index from current collection
.index( )Get the position of an element in current collection
.hasClass( )Check if any elements in the collection have the specified class

####Examples####

NSLog(@"options: %@", document.Query(@"body").find(@"#select").find(@"option"));
NSLog(@"title: %@", document.Query(@"title").text());
NSLog(@"attribute: %@", document.Query(@"select").first().attr(@"id"));
NSLog(@"class: %@", document.Query(@"#select").parents(@".main"));
NSLog(@"tag.class: %@", document.Query(@"div.theCls"));
NSLog(@"tag#id : %@", document.Query(@"div#theId"));

Contact

Weibo: @TracyYih

Email: [email protected]

License

Apache License

ocgumbo's People

Contributors

tracy-e avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.