introduce
We open the official website of goquery./PuerkitoBio/goqueryThe following is the official introduction: goquery is the go language jQuery
goquery brings a syntax similar to jQuery to the Go language and a set of functions.
It is based on Go's net/html package and the CSS selector library cascadia. Since the net/html parser returns a node instead of a fully functional DOM tree, jQuery's state operation functions (such as height(), css(), detach()) have been abandoned.
Quote
In addition, because the net/html parser requires UTF-8 encoding, goquery also requires: the caller is responsible for ensuring that the source document provides UTF-8 encoding HTML. See the wiki for various options to do this.
Quote
In terms of syntax, it is as close to jQuery as possible, using the same function name as possible, and a warm and fuzzy linkable interface. jQuery is a super popular library, and I think writing a similar HTML manipulation library is better to follow its API rather than start over (the same spirit as Go's packages), although some of its methods are fmt than intuitive (look at you, index() ...).
Install
go get /PuerkitoBio/goquery
use
package goquery import ( "log" "net/http" "testing" "/PuerkitoBio/goquery" ) func TestName(t *) { // Request the HTML page. res, err := ("") if err != nil { (err) } defer () if != 200 { ("status code error: %d %s", , ) } // Load the HTML document doc, err := () if err != nil { (err) } title := ("title") (()) }
The above is the detailed content of goquery introduction (installation and use tutorial). For more information about goquery installation and use, please follow my other related articles!