Compare commits

..
10 Commits
13 changed files with 26 additions and 26 deletions
+2
View File
@@ -1,2 +1,4 @@
*.sublime-*
.DS_Store
*.swp
#*.*#
+12 -14
View File
@@ -1,6 +1,6 @@
# goquery - a little like that j-thing, only in Go
GoQuery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on the [experimental html package][exphtml] and the CSS Selector library [cascadia][]. Since the experimental html parser returns tokens (nodes), and not a full-featured DOM object, jQuery's manipulation and modification functions have been left off (no point in modifying data in the parsed tree of the HTML, it has no effect).
GoQuery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on the experimental html package and the CSS Selector library [cascadia][]. Since the experimental html parser returns tokens (nodes), and not a full-featured DOM object, jQuery's manipulation and modification functions have been left off (no point in modifying data in the parsed tree of the HTML, it has no effect).
Supported functions are query-oriented features (`hasClass()`, `attr()` and the likes), as well as traversing functions that make sense given what we have to work with. This makes GoQuery a great library for scraping web pages.
@@ -8,22 +8,21 @@ Syntax-wise, it is as close as possible to jQuery, with the same function names
## Installation
Since this library (and cascadia) depends on the experimental branch, this package must be installed first. Both GoQuery and Cascadia expect to find the experimental library with the `"exp/html"` import statement. To install it at this location, please [follow this guide][wikiexp].
$ go get github.com/PuerkitoBio/goquery
Once this is done, install GoQuery:
(optional) To run unit tests:
$ cd $GOPATH/src/github.com/PuerkitoBio/goquery
$ go test
`go get github.com/PuerkitoBio/goquery`
(optional) To run benchmarks:
To run unit tests, run this command in goquery's source directory (`$GOPATH/src/github.com/PuerkitoBio/goquery`):
`go test`
To run benchmarks, run this command in goquery's source directory:
`go test -bench=".*"`
$ cd $GOPATH/src/github.com/PuerkitoBio/goquery
$ go test -bench=".*"
## Changelog
* **v0.2.1** : Make go-getable, now that [go.net/html is Go1.0-compatible][gonet] (thanks to @matrixik for pointing this out).
* **v0.2.0** : Add support for negative indices in Slice(). **BREAKING CHANGE** `Document.Root` is removed, `Document` is now a `Selection` itself (a selection of one, the root element, just like `Document.Root` was before). Add jQuery's Closest() method.
* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases).
* **v0.1.0** : Initial release.
@@ -98,11 +97,10 @@ The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia'
[jquery]: http://jquery.com/
[go]: http://golang.org/
[exphtml]: http://code.google.com/p/go/source/browse#hg%2Fsrc%2Fpkg%2Fexp
[cascadia]: http://code.google.com/p/cascadia/
[wikiexp]: http://code.google.com/p/go-wiki/wiki/InstallingExp
[bsd]: http://opensource.org/licenses/BSD-3-Clause
[golic]: http://golang.org/LICENSE
[caslic]: http://code.google.com/p/cascadia/source/browse/LICENSE
[doc]: http://go.pkgdoc.org/github.com/puerkitobio/goquery
[doc]: http://godoc.org/github.com/PuerkitoBio/goquery
[index]: http://api.jquery.com/index/
[gonet]: http://code.google.com/p/go/source/detail?r=f7f5159120f51ba0070774d3c5907969b5fe7858&repo=net
+2 -2
View File
@@ -1,7 +1,7 @@
package goquery
import (
"exp/html"
"code.google.com/p/go.net/html"
)
// First() reduces the set of matched elements to the first in the set.
@@ -28,7 +28,7 @@ func (this *Selection) Eq(index int) *Selection {
}
// Slice() reduces the set of matched elements to a subset specified by a range
// of indices. At the moment, negative indices are not supported.
// of indices.
func (this *Selection) Slice(start int, end int) *Selection {
if start < 0 {
start += len(this.Nodes)
+1 -1
View File
@@ -26,7 +26,7 @@ Package goquery implements features similar to jQuery, including the chainable
syntax, to manipulate and query an HTML document (the modification functions of jQuery are not included).
It depends on Go's experimental html package, which must be installed so that it
can be imported as "exp/html". See this tutorial on how to install it
can be imported as "code.google.com/p/go.net/html". See this tutorial on how to install it
accordingly: http://code.google.com/p/go-wiki/wiki/InstallingExp
It uses Cascadia as CSS selector (similar to Sizzle for jQuery). This dependency
+1 -1
View File
@@ -1,7 +1,7 @@
package goquery
import (
"exp/html"
"code.google.com/p/go.net/html"
)
// Add() adds the selector string's matching nodes to those in the current
+1 -1
View File
@@ -2,7 +2,7 @@ package goquery
import (
"code.google.com/p/cascadia"
"exp/html"
"code.google.com/p/go.net/html"
)
// Filter() reduces the set of matched elements to those that match the selector string.
+1 -1
View File
@@ -1,7 +1,7 @@
package goquery
import (
"exp/html"
"code.google.com/p/go.net/html"
"testing"
)
+1 -1
View File
@@ -2,7 +2,7 @@ package goquery
import (
"bytes"
"exp/html"
"code.google.com/p/go.net/html"
)
// Attr() gets the specified attribute's value for the first element in the
+1 -1
View File
@@ -2,7 +2,7 @@ package goquery
import (
"code.google.com/p/cascadia"
"exp/html"
"code.google.com/p/go.net/html"
"regexp"
"strings"
)
+1 -1
View File
@@ -2,7 +2,7 @@ package goquery
import (
"code.google.com/p/cascadia"
"exp/html"
"code.google.com/p/go.net/html"
)
type siblingType int
+1 -1
View File
@@ -1,7 +1,7 @@
package goquery
import (
"exp/html"
"code.google.com/p/go.net/html"
"net/http"
"net/url"
)
+1 -1
View File
@@ -1,7 +1,7 @@
package goquery
import (
"exp/html"
"code.google.com/p/go.net/html"
"fmt"
"os"
"testing"
+1 -1
View File
@@ -1,7 +1,7 @@
package goquery
import (
"exp/html"
"code.google.com/p/go.net/html"
)
func getChildren(n *html.Node) (result []*html.Node) {