antchfx / htmlquery

htmlquery is golang XPath package for HTML query.
https://github.com/antchfx/xpath
MIT License
723 stars 73 forks source link

Can't get node by their index #42

Closed koteesy closed 3 years ago

koteesy commented 3 years ago

Hello, thanks for great library!

For example, we have some piece of xpath, which give me a valid node when i test in browser:

(//table//tbody)[7]

But if i specify it in library, like:

filePath := "./test.html"

doc, er := htmlquery.LoadDoc(filePath)

if er != nil {
  log.Fatal(er)
}

expr, _ := xpath.Compile("(//table//tbody)[7]")

v := expr.Evaluate(htmlquery.CreateXPathNavigator(doc))

values, ok := v.(*xpath.NodeIterator)

if ok {
    for values.MoveNext() {
        log.Println("Founded value is", values.Current().Value())
    }
}else {
    log.Println("Not node iterator.")
}

The output will be empty, because library not found any node. Soo... My question is simple, do i do something wrong, or it bug in library?

HTML ``` Testing
  
Tracking No.
First name: First name..
Second: Second name..
No. Date Time Area Status Status(KOR) Remarks
1 2021.03.22 10:22 Korea Oks Test Some new info
```
koteesy commented 3 years ago

Hello :d

Any updates?

zhengchun commented 3 years ago

Fixed. you can checkout the latest of xpath package to fix this.

https://github.com/antchfx/xpath/commit/50cf86ee613f95d93bcb5fad63ffd495c5a3c3a2

koteesy commented 3 years ago

Fixed. you can checkout the latest of xpath package to fix this.

antchfx/xpath@50cf86e

Thank you so much! I will check it.

koteesy commented 3 years ago

Look's like everything working fine. Thanks you!