lizongying / go-xpath

XPath Selector in Golang for Easier Use.

Home Page:https://pkg.go.dev/github.com/lizongying/go-xpath

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-xpath

XPath Selector in Golang for Easier Use.

go-xpath

document

中文

Install

go get -u github.com/lizongying/go-xpath@latest

Usage

For more usage, please refer to the test selector_test

package main

import (
	"fmt"
	"github.com/lizongying/go-xpath/xpath"
)

func main() {
	html := `<html class="abc">....<div class="def">....</div><div class="gkl">123</div></html>`
	x, _ := xpath.NewSelectorFromStr(html)

	s := x.FindStrOne(`//div[@class="def"]/text()`)
	//....
	fmt.Println(s)

	i := x.FindIntOneOr(`//div[@class="gkl"]/text()`, 111)
	//123
	fmt.Println(i)

	i = x.FindIntOneOr(`//div[@class="mn"]/text()`, 111)
	//111
	fmt.Println(i)

	sl := x.FindStrMany(`//div/text()`)
	//[.... 123]
	fmt.Println(sl)

	s = x.FindNodeOne(`//html[@class="abc"]`).FindStrOne(`.//div[@class="gkl"]`)
	//123
	fmt.Println(s)
}

About

XPath Selector in Golang for Easier Use.

https://pkg.go.dev/github.com/lizongying/go-xpath

License:MIT License


Languages

Language:Go 100.0%