Skip to content
 
 

Latest commit

 

History

689 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gokogiri

Build Status codecov Go Report Card GoDoc

Pure-Go XML/HTML DOM and XPath library

Gokogiri is a pure-Go library providing a DOM-like interface for XML and HTML documents, inspired by the Ruby Nokogiri API. It allows you to parse, manipulate, and create HTML and XML documents. Nodes can be selected using CSS selectors (in much the same fashion as jQuery) or XPath 1.0 expressions.

Version 5.1+ is a pure-Go implementation with zero C dependencies. Earlier versions required libxml2/libxslt C libraries.

Installation

go get github.com/freemed/gokogiri

Running tests

go test github.com/freemed/gokogiri/...

Basic example

package main

import (
  "net/http"
  "io"
  "github.com/freemed/gokogiri"
)

func main() {
  // fetch and read a web page
  resp, _ := http.Get("http://www.google.com")
  page, _ := io.ReadAll(resp.Body)

  // parse the web page
  doc, _ := gokogiri.ParseHtml(page)

  // perform operations on the parsed page -- consult the tests for examples

  // important -- don't forget to free the resources when you're done!
  doc.Free()
}

About

A light libxml wrapper for Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages