-
Notifications
You must be signed in to change notification settings - Fork 88
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
元素属性值输出问题 #4
Comments
xpath库目前并不支持直接输出@属性值,它默认返回是包括指定@的元素,也就是一个 elem := htmlquery.FindOne(root, `//img/@src`)
fmt.Println(htmlquery.SelectAttr(elem,"src")) 类似于这个: |
OK,这个问题我大概调试出来了。
我将htmlNodeNavigator暴露出来,然后就能直接输出值了。 |
实际上是支持输出@属性值的,感谢作者的付出! |
感谢支持 😄 |
我的测试代码:
|
Hi, @gofmt ,向使用者暴露 你的这个问题关于直接输出@属性值的,我之前有考虑过,实现一个Compile方法,并返回指定XPath查询的值(它可能是数字,可能是字符串,也可以是一个Node列表)。e5682c1#diff-04c6e90faac2675aa89e2176d2eec7d8L120 |
OK,期待! |
expr, err := xpath.Compile("//img/@src")
val := expr.Evaluate(nav)
switch typ := val.(type) {
case *xpath.NodeIterator:
for typ.MoveNext() {
fmt.Println(typ.Current().Value()) // output @src value
}
} xpath_testL184 |
一直没明白如何输出://img/@src 这样的xpath规则的结果。
我期望的是输出元素img的属性src的值,请帮助我,谢谢!
The text was updated successfully, but these errors were encountered: