antchfx/htmlquery

Attribute selector bug?

Closed this issue · 2 comments

Hello,

I think the attribute selector, e.g. "@href", should return the value of the attribute, NOT the name of the attribute.

func TestAttributeSelector(t * testing.T) {

	s := `<doc><a href="example.com"></a></doc>`
	doc, _ := htmlquery.Parse(strings.NewReader(s))
	a := htmlquery.FindOne(doc, "//a/@href")
	if a.Data != "example.com" {
		t.Errorf("Expected 'example.com' : got %s", a.Data)
	}
}

you should use htmlquery.InnerText() to get the value.

s := `<doc><a href="example.com"></a></doc>`
doc, _ := htmlquery.Parse(strings.NewReader(s))
a := htmlquery.FindOne(doc, "//a/@href")
if htmlquery.InnerText(a) != "example.com" {
	fmt.Println("error")
}