mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
Go syntax
Go syntax colouring added.
This commit is contained in:
+3
-3
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
The `go.net/html` package used by `goquery` requires that the html document is UTF-8 encoded. When you know the encoding of the html page is not UTF-8, you can use the `iconv` package to convert it to UTF-8 (there are various implementation of the `iconv` API, see [godoc.org][iconv] for other options):
|
The `go.net/html` package used by `goquery` requires that the html document is UTF-8 encoded. When you know the encoding of the html page is not UTF-8, you can use the `iconv` package to convert it to UTF-8 (there are various implementation of the `iconv` API, see [godoc.org][iconv] for other options):
|
||||||
|
|
||||||
```
|
```bash
|
||||||
$ go get -u github.com/djimenez/iconv-go
|
$ go get -u github.com/djimenez/iconv-go
|
||||||
```
|
```
|
||||||
|
|
||||||
and then:
|
and then:
|
||||||
|
|
||||||
```
|
```golang
|
||||||
// Load the URL
|
// Load the URL
|
||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -51,7 +51,7 @@ You can find a code example using `otto` [in this gist][exotto]. Thanks to githu
|
|||||||
|
|
||||||
If all you need is a normal `for` loop over all nodes in the current selection, where `Map/Each`-style iteration is not necessary, you can use the following:
|
If all you need is a normal `for` loop over all nodes in the current selection, where `Map/Each`-style iteration is not necessary, you can use the following:
|
||||||
|
|
||||||
```
|
```golang
|
||||||
sel := Doc().Find(".selector")
|
sel := Doc().Find(".selector")
|
||||||
for i := range sel.Nodes {
|
for i := range sel.Nodes {
|
||||||
single := sel.Eq(i)
|
single := sel.Eq(i)
|
||||||
|
|||||||
Reference in New Issue
Block a user