Skip to content

Commit 298aa1f

Browse files
committed
Add an example
1 parent 3edc375 commit 298aa1f

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,65 @@
11
# GoHTML
2+
23
A powerful and comprehensive HTML parser and DOM manipulation library for Go, bringing JavaScript-like DOM operations to the Go ecosystem.
34

45
## Installation
5-
Run the following command in project directory in order to install.
6+
7+
Run the following command in project directory in order to install.
8+
69
```bash
710
go get github.com/udan-jayanith/GoHTML
811
```
912

1013
Then GoHTML can import like this.
14+
1115
```go
1216
import (
1317
GoHtml "github.com/udan-jayanith/GoHTML"
1418
)
1519
```
1620

1721
## Features
18-
* Parsing
19-
* Serialization
20-
* Node tree traversing
21-
* Querying
22+
23+
- Parsing
24+
- Serialization
25+
- Node tree traversing
26+
- Querying
27+
28+
## Example
29+
Heres an example of fetching a website and parsing and then using querying methods.
30+
```go
31+
res, err := http.Get("https://www.metalsucks.net/")
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
36+
//Parses the given html reader and then returns the root node and an error.
37+
node, err := GoHtml.Decode(res.Body)
38+
if err != nil {
39+
t.Fatal(err)
40+
}
41+
42+
nodeList := node.GetElementsByClassName("post-title")
43+
iter := nodeList.IterNodeList()
44+
for node := range iter{
45+
print(node.GetInnerText())
46+
}
47+
```
2248

2349
## Changelog
50+
2451
Changes, bug fixes and new features in this version.
52+
2553
- add: NodeList
2654
- add: Querying helper functions
2755
- add: ClassList
2856
- bug fix: Empty attribute value parsing bug fixed
2957
- changed: Renamed GetTraverser to NewTraverser
3058

3159
## Documentation
60+
3261
Fully fledged [documentation](https://pkg.go.dev/github.com/udan-jayanith/GoHTML) is available at [go.pkg](https://pkg.go.dev/)
3362

3463
## Contributions
64+
3565
Contributions are welcome and pull requests and issues will be viewed by an official.

0 commit comments

Comments
 (0)