Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions soup.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ func matchElementName(n *html.Node, name string) bool {

// Using depth first search to find the first occurrence and return
func findOnce(n *html.Node, args []string, uni bool, strict bool) (*html.Node, bool) {
if n == nil {
return nil, false
}
if uni == true {
if n.Type == html.ElementNode && matchElementName(n, args[0]) {
if len(args) > 1 && len(args) < 4 {
Expand Down Expand Up @@ -510,6 +513,9 @@ func findOnce(n *html.Node, args []string, uni bool, strict bool) (*html.Node, b

// Using depth first search to find all occurrences and return
func findAllofem(n *html.Node, args []string, strict bool) []*html.Node {
if n == nil {
return nil
}
var nodeLinks = make([]*html.Node, 0, 10)
var f func(*html.Node, []string, bool)
f = func(n *html.Node, args []string, uni bool) {
Expand Down
9 changes: 8 additions & 1 deletion soup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package soup

import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -91,6 +92,13 @@ func TestFind(t *testing.T) {
assert.Equal(t, "Last one", actual)
}

func TestFindOnceReturnsNil(t *testing.T) {
// FindOnce()
tag := "some tag"
actual := doc.Find(tag)
assert.Equal(t, fmt.Sprintf("element `%s` with attributes `%s` not found", tag, ""), actual.Error.Error())
}

func TestFindNextPrevElement(t *testing.T) {
// FindNextSibling() and NodeValue field
actual := doc.Find("div", "id", "0").FindNextSibling().NodeValue
Expand Down Expand Up @@ -290,5 +298,4 @@ func TestClient_PostForm(t *testing.T) {
func TestHTML(t *testing.T) {
li := doc.Find("ul").Find("li")
assert.Equal(t, "<li>To a <a href=\"hello.jsp\">JSP page</a> right?</li>", li.HTML())

}