Closed waldner closed 1 year ago
@waldner, Hello, your xpath is correct, but the Golang's html parser package will automatic append tbody
element into the table
element.
fmt.Println(htmlquery.OutputHTML(tree, true))
output:
<table class="generictable" width="100%" border="1" cellpadding="0" cellspacing="0">
<tbody><tr><td class="hidden">XXXX</td></tr>
<tr class="foo" id="222222"><td class="hidden">1234</td></tr>
</tbody></table>
So just change to fmt.Println(htmlquery.Find(tree, "//div[@id='main']/table/tbody/tr[@class='foo']"))
Ok, now that you mentioned the parser I did some research and I found this post which explains a bit what's going on: https://nikodoko.com/posts/html-table-parsing/ (I'm putting the link here in case someone else coming from google encounters the same problem).
Thanks!
Here's a simple reproducer:
Output:
This is all pretty basic stuff, and all four Xpath expressions successfully match nodes with python's lxml, for example. Am I doing something wrong?