Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute selector bug? #11

Closed
peterstark72 opened this issue May 11, 2019 · 2 comments
Closed

Attribute selector bug? #11

peterstark72 opened this issue May 11, 2019 · 2 comments

Comments

@peterstark72
Copy link

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
Copy link
Contributor

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
Copy link
Author

peterstark72 commented May 11, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants