Skip to content
An Objective-C HTML5 parser based on Google Gumbo.
Objective-C Roff
Branch: master
Clone or download
Latest commit 4a0abe2 Sep 16, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
OCGumbo fix a crash Sep 14, 2018
Tests update example Apr 21, 2017
.gitignore Initial commit Aug 17, 2013
.gitmodules submodule Aug 29, 2013
LICENSE Initial commit Aug 17, 2013 update example Apr 21, 2017

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.


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


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


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

Query APIs

.Query( )Query children elements from current node by selector
.text( )Get the combined text contents of current object
.textArray( )Get the combined text array 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


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"));


Weibo: @TracyYih



Apache License

You can’t perform that action at this time.