docs: Add LICENSE and README.md

This commit is contained in:
ptrcnull 2023-03-27 00:20:40 +02:00
parent f84ae8d1fd
commit 3a413c5335
Signed by: ptrcnull
GPG key ID: 411F7B30801DD9CA
2 changed files with 51 additions and 0 deletions

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
Copyright (c) 2023 ptrcnull
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

42
README.md Normal file
View file

@ -0,0 +1,42 @@
# ptrcnull/html
library wrapping `net/html` with a bunch of convenience functions
example usage:
```go
package main
import (
"log"
"os"
"git.ddd.rip/ptrcnull/html"
)
func main() {
htmlText := getSomeHtmlPage()
document, err := html.ParseDocument(htmlText)
if err != nil {
log.Fatalf("parse document: %w\n", err)
}
table := document.QuerySelector("table")
if table == nil {
log.Fatalln("table not found")
}
if os.Getenv("DEBUG") == "1" {
log.Println("table:", table.Render())
}
for _, row := range table.QuerySelectorAll("tr") {
if strings.Contains(row.Text(), "a thing you're looking for") {
cell := row.FindOne(func(n *html.Node) {
return n.HasAttr("aria-label") && n.GetAttr("aria-label")[0] == "Value"
})
log.Println("value:", cell.TrimmedText())
}
}
}
```