From dedfe1813b195be907e6db3cf0c9323dc0eb9557 Mon Sep 17 00:00:00 2001 From: zhengchun Date: Thu, 21 Mar 2024 00:09:22 +0800 Subject: [PATCH 1/4] new `testing.yml` --- .github/workflows/testing.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..5ed662a --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,24 @@ +name: Testing +on: [push, pull_request] + +jobs: + test: + strategy: + matrix: + go-version: ["1.20", 1.21.x, 1.22.x] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + + steps: + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Test + run: | + go version + go test . -v -cover From afa9b2f1a8e410112a36376c477e38e429bf080d Mon Sep 17 00:00:00 2001 From: zhengchun Date: Thu, 21 Mar 2024 00:10:19 +0800 Subject: [PATCH 2/4] remove the deprecated `.travis.yml` --- .travis.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 86da84a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: go - -go: - - 1.9.x - - 1.12.x - - 1.13.x - -install: - - go get golang.org/x/net/html/charset - - go get golang.org/x/net/html - - go get github.com/antchfx/xpath - - go get github.com/mattn/goveralls - - go get github.com/golang/groupcache - -script: - - $HOME/gopath/bin/goveralls -service=travis-ci \ No newline at end of file From fe057a43f8e702b45ae41c5909d47ab316eeadef Mon Sep 17 00:00:00 2001 From: zhengchun Date: Thu, 21 Mar 2024 00:15:32 +0800 Subject: [PATCH 3/4] update `testing status` badge --- README.md | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5eb290d..652572f 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,32 @@ -htmlquery -==== -[![Build Status](https://travis-ci.org/antchfx/htmlquery.svg?branch=master)](https://travis-ci.org/antchfx/htmlquery) -[![Coverage Status](https://coveralls.io/repos/github/antchfx/htmlquery/badge.svg?branch=master)](https://coveralls.io/github/antchfx/htmlquery?branch=master) +# htmlquery + +[![Build Status](https://github.com/antchfx/htmlquery/actions/workflows/testing.yml/badge.svg)](https://github.com/antchfx/htmlquery/actions/workflows/testing.yml) [![GoDoc](https://godoc.org/github.com/antchfx/htmlquery?status.svg)](https://godoc.org/github.com/antchfx/htmlquery) [![Go Report Card](https://goreportcard.com/badge/github.com/antchfx/htmlquery)](https://goreportcard.com/report/github.com/antchfx/htmlquery) -Overview -==== +# Overview `htmlquery` is an XPath query package for HTML, lets you extract data or evaluate from HTML documents by an XPath expression. -`htmlquery` built-in the query object caching feature based on [LRU](https://godoc.org/github.com/golang/groupcache/lru), this feature will caching the recently used XPATH query string. Enable query caching can avoid re-compile XPath expression each query. +`htmlquery` built-in the query object caching feature based on [LRU](https://godoc.org/github.com/golang/groupcache/lru), this feature will caching the recently used XPATH query string. Enable query caching can avoid re-compile XPath expression each query. You can visit this page to learn about the supported XPath(1.0/2.0) syntax. https://github.com/antchfx/xpath -XPath query packages for Go -=== +# XPath query packages for Go + | Name | Description | | ------------------------------------------------- | ----------------------------------------- | | [htmlquery](https://github.com/antchfx/htmlquery) | XPath query package for the HTML document | | [xmlquery](https://github.com/antchfx/xmlquery) | XPath query package for the XML document | | [jsonquery](https://github.com/antchfx/jsonquery) | XPath query package for the JSON document | -Installation -==== +# Installation ``` go get github.com/antchfx/htmlquery ``` -Getting Started -==== +# Getting Started #### Query, returns matched elements or error. @@ -70,13 +66,13 @@ list := htmlquery.Find(doc, "//a") #### Find all A elements that have `href` attribute. ```go -list := htmlquery.Find(doc, "//a[@href]") +list := htmlquery.Find(doc, "//a[@href]") ``` #### Find all A elements with `href` attribute and only return `href` value. ```go -list := htmlquery.Find(doc, "//a/@href") +list := htmlquery.Find(doc, "//a/@href") for _ , n := range list{ fmt.Println(htmlquery.SelectAttr(n, "href")) // output @href value } @@ -89,6 +85,7 @@ a := htmlquery.FindOne(doc, "//a[3]") ``` ### Find children element (img) under A `href` and print the source + ```go a := htmlquery.FindOne(doc, "//a") img := htmlquery.FindOne(a, "//img") @@ -103,9 +100,7 @@ v := expr.Evaluate(htmlquery.CreateXPathNavigator(doc)).(float64) fmt.Printf("total count is %f", v) ``` - -Quick Starts -=== +# Quick Starts ```go func main() { @@ -127,9 +122,7 @@ func main() { } ``` - -FAQ -==== +# FAQ #### `Find()` vs `QueryAll()`, which is better? @@ -158,6 +151,6 @@ BenchmarkDisableSelectorCache-4 500000 3162 ns/op htmlquery.DisableSelectorCache = true ``` -Questions -=== +# Questions + Please let me know if you have any questions. From 040ad909c3d722802d9d148cc67a6ffd73160f3a Mon Sep 17 00:00:00 2001 From: zhengchun Date: Thu, 21 Mar 2024 00:16:36 +0800 Subject: [PATCH 4/4] update an example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 652572f..ee4d473 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ list := htmlquery.Find(doc, "//a[@href]") ```go list := htmlquery.Find(doc, "//a/@href") for _ , n := range list{ - fmt.Println(htmlquery.SelectAttr(n, "href")) // output @href value + fmt.Println(htmlquery.InnerText(n)) // output @href value } ```