mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
remove wiki section on big docs, cascadia is now almost as fast as workarounds
This commit is contained in:
-23
@@ -1,28 +1,5 @@
|
||||
# Tips and tricks
|
||||
|
||||
## Manipulate Big Documents
|
||||
|
||||
Some CSS selectors are inherently slower than others, and when manipulating big documents (e.g. tables with thousands of rows), the performance may suffer. In particular, pseudo-classes such as `:nth-child` are slow, and while they are handy when manipulating smaller documents, they can be painful for bigger ones.
|
||||
|
||||
In those cases, it can be order of magnitudes faster to use a simpler CSS selector and use goquery methods to do the finer-grained filtering.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
doc, err := goquery.NewDocumentFromReader(bigDocument)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// this could be much slower...
|
||||
sel := doc.Find("#bigtable tr:nth-child(1) td")
|
||||
|
||||
// than this:
|
||||
sel := doc.Find("#bigtable tr").First().Find("td")
|
||||
```
|
||||
|
||||
Other indexes in an `:nth-child(x)` can be translated to `sel.Eq(x)`.
|
||||
|
||||
## Handle Non-UTF8 html Pages
|
||||
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user