mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8c788f298 | ||
|
|
faf9b4dc84 | ||
|
|
a751e062fd | ||
|
|
b6dc0bd0ea | ||
|
|
4110e175b5 | ||
|
|
d35d4cec3e | ||
|
|
11e1233457 | ||
|
|
98eb88c22b | ||
|
|
6a7f1c4a50 | ||
|
|
7307e2457c | ||
|
|
a7412da07a | ||
|
|
c5eeb05f52 | ||
|
|
372d5bdaa0 | ||
|
|
5dfda0e354 | ||
|
|
d6951d24bb | ||
|
|
c09491e08b | ||
|
|
02e233c33a |
@@ -1,104 +0,0 @@
|
||||
image: fedora/latest
|
||||
packages:
|
||||
- tar
|
||||
environment:
|
||||
GOROOT: /tmp/go
|
||||
GOPATH: /home/build
|
||||
GOBIN: /home/build/bin
|
||||
sources:
|
||||
- https://github.com/PuerkitoBio/goquery
|
||||
tasks:
|
||||
- setup: |
|
||||
mkdir bin
|
||||
mkdir -p src/github.com/PuerkitoBio
|
||||
mv goquery src/github.com/PuerkitoBio/
|
||||
- go1_7: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.7.6.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_8: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.8.7.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_9: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.9.7.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_10: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.10.8.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_11: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.11.13.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_12: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.12.17.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_13: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.13.15.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_14: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.14.12.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_15: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.15.5.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
- go1_16: |
|
||||
cd /tmp
|
||||
rm -rf go
|
||||
curl -Lo golang.tar.gz https://golang.org/dl/go1.16beta1.linux-amd64.tar.gz
|
||||
tar xvf golang.tar.gz
|
||||
cd /home/build/src/github.com/PuerkitoBio/goquery
|
||||
/tmp/go/bin/go version
|
||||
/tmp/go/bin/go get -t .
|
||||
/tmp/go/bin/go test -v
|
||||
@@ -0,0 +1,7 @@
|
||||
version: 2
|
||||
updates:
|
||||
# Maintain dependencies for Go
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
@@ -0,0 +1,25 @@
|
||||
name: test
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
GOPROXY: https://proxy.golang.org,direct
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.16.x, 1.17.x]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Test
|
||||
run: go test ./... -v -cover
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
arch:
|
||||
- amd64
|
||||
- ppc64le
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
- 1.13.x
|
||||
- 1.14.x
|
||||
- 1.15.x
|
||||
- tip
|
||||
|
||||
jobs:
|
||||
exclude:
|
||||
- arch: ppc64le
|
||||
go: 1.7.x
|
||||
- arch: ppc64le
|
||||
go: 1.8.x
|
||||
- arch: ppc64le
|
||||
go: 1.9.x
|
||||
- arch: ppc64le
|
||||
go: 1.10.x
|
||||
- arch: ppc64le
|
||||
go: 1.11.x
|
||||
- arch: ppc64le
|
||||
go: 1.12.x
|
||||
@@ -1,5 +1,8 @@
|
||||
# goquery - a little like that j-thing, only in Go
|
||||
[](https://builds.sr.ht/~mna/goquery/commits/fedora.yml?) [](http://travis-ci.org/PuerkitoBio/goquery) [](https://pkg.go.dev/github.com/PuerkitoBio/goquery) [](https://sourcegraph.com/github.com/PuerkitoBio/goquery?badge)
|
||||
|
||||
[](https://github.com/PuerkitoBio/goquery/actions)
|
||||
[](https://pkg.go.dev/github.com/PuerkitoBio/goquery)
|
||||
[](https://sourcegraph.com/github.com/PuerkitoBio/goquery?badge)
|
||||
|
||||
goquery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on Go's [net/html package][html] and the CSS Selector library [cascadia][]. Since the net/html parser returns nodes, and not a full-featured DOM tree, jQuery's stateful manipulation functions (like height(), css(), detach()) have been left off.
|
||||
|
||||
@@ -37,6 +40,8 @@ Please note that because of the net/html dependency, goquery requires Go1.1+ and
|
||||
|
||||
**Note that goquery's API is now stable, and will not break.**
|
||||
|
||||
* **2021-10-25 (v1.8.0)** : Add `Render` function to render a `Selection` to an `io.Writer` (thanks [@anthonygedeon](https://github.com/anthonygedeon)).
|
||||
* **2021-07-11 (v1.7.1)** : Update go.mod dependencies and add dependabot config (thanks [@jauderho](https://github.com/jauderho)).
|
||||
* **2021-06-14 (v1.7.0)** : Add `Single` and `SingleMatcher` functions to optimize first-match selection (thanks [@gdollardollar](https://github.com/gdollardollar)).
|
||||
* **2021-01-11 (v1.6.1)** : Fix panic when calling `{Prepend,Append,Set}Html` on a `Selection` that contains non-Element nodes.
|
||||
* **2020-10-08 (v1.6.0)** : Parse html in context of the container node for all functions that deal with html strings (`AfterHtml`, `AppendHtml`, etc.). Thanks to [@thiemok][thiemok] and [@davidjwilkins][djw] for their work on this.
|
||||
|
||||
@@ -46,6 +46,6 @@ func BenchmarkHtml(b *testing.B) {
|
||||
sel := DocW().Find("h2")
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
sel.Html()
|
||||
_, _ = sel.Html()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module github.com/PuerkitoBio/goquery
|
||||
|
||||
require (
|
||||
github.com/andybalholm/cascadia v1.1.0
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
|
||||
github.com/andybalholm/cascadia v1.3.1
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8
|
||||
)
|
||||
|
||||
go 1.13
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
|
||||
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 h1:/6y1LfuqNuQdHAm0jjtPtgRcxIxjVZgm5OTu8/QhZvk=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
||||
+14
-7
@@ -2,6 +2,7 @@ package goquery
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
@@ -50,13 +51,24 @@ func nodeName(node *html.Node) string {
|
||||
case html.ElementNode, html.DoctypeNode:
|
||||
return node.Data
|
||||
default:
|
||||
if node.Type >= 0 && int(node.Type) < len(nodeNames) {
|
||||
if int(node.Type) < len(nodeNames) {
|
||||
return nodeNames[node.Type]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Render renders the html of the first element from selector and writes it to
|
||||
// the writer. It behaves the same as OuterHtml but writes to w instead of
|
||||
// returning the string.
|
||||
func Render(w io.Writer, s *Selection) error {
|
||||
if s.Length() == 0 {
|
||||
return nil
|
||||
}
|
||||
n := s.Get(0)
|
||||
return html.Render(w, n)
|
||||
}
|
||||
|
||||
// OuterHtml returns the outer HTML rendering of the first item in
|
||||
// the selection - that is, the HTML including the first element's
|
||||
// tag and attributes.
|
||||
@@ -66,12 +78,7 @@ func nodeName(node *html.Node) string {
|
||||
// a property provided by the DOM).
|
||||
func OuterHtml(s *Selection) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if s.Length() == 0 {
|
||||
return "", nil
|
||||
}
|
||||
n := s.Get(0)
|
||||
if err := html.Render(&buf, n); err != nil {
|
||||
if err := Render(&buf, s); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buf.String(), nil
|
||||
|
||||
Reference in New Issue
Block a user