Attribute selector bug?
Closed this issue · 2 comments
peterstark72 commented
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)
}
}
zhengchun commented
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")
}
peterstark72 commented
Doh!
Thanks.
//Peter
Den lör 11 maj 2019 kl 14:45 skrev zhengchun <notifications@github.com>:
… 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, ***@***.***")if htmlquery.InnerText(a) != "example.com" {
fmt.Println("error")
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADT3UDEGCCZRE5D7B32G5TPU25X5ANCNFSM4HMHOV2Q>
.