Skip to content

Find returns an element when passed an invalid xpath #52

Closed
@iambodi

Description

package main

import (
	"fmt"
	"strings"

	"github.com/antchfx/htmlquery"
)

const html = `<html>
<body>
<div>
    <ul id="food">
        <li>avocado</li>
    </ul>
</div>
</body>
</html>`

const xpath = `//*[contains(@id,"food")]//*[contains(@id,"food")]//*[contains(text(),"avocado")]`

func main() {
	doc, err := htmlquery.Parse(strings.NewReader(html))
	if err != nil {
		panic(err)
	}

	list := htmlquery.Find(doc, xpath)

	node := list[0]
	fmt.Println(node.Data, node.FirstChild.Data, node.Parent.Data)
}

Hi,

I have an issue with the Find method. When passed an invalid xpath (confirmed by the HTML inspector of Chrome and Firefox), it returns a node.

On playground: https://go.dev/play/p/3Z6jtSNsYfx

Thank you !

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions