Can't get node by their index
koteesy opened this issue · 4 comments
koteesy commented
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Show loading image - place at the bottom of the page -->
<div class="modal_loading"></div>
<div style="margin: 0px auto; width: 600px;">
<table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td align="left" width="100%">
<table border="0" width="100%" height="100">
<tbody>
<tr>
<td align="left" valign="middle" width="150"> <img width="120" src="/logo.png" border="0" /></td>
<td>
<form name="form2" id="form2" method="post" data-ajax="false">
<input type="hidden" name="mode" value="search" />
<table border="0" width="100%">
<tbody>
<tr>
<td height="40" colspan="3"></td>
</tr>
<tr>
<td align="center" width="120">Tracking No.</td>
<td align="right" width="220"><input type="text" id="search_no" name="search_no" placeholder="Enter value" maxlength="30" style="height: 44px" onclick="this.select();" /></td>
<td align="right"><button type="submit" id="btnSubmit" style="width: 100px;">Query</button></td>
</tr>
<tr>
<td align="right" width="180" colspan="3"><span id="show_msg_01"></span></td>
</tr>
<tr>
<td align="right" width="180" colspan="3"><span id="tracking_info"></span></td>
</tr>
<tr>
<td align="right" width="180" colspan="3"><span id="contact_info"></span></td>
</tr>
<tr>
<td align="right" height="20" colspan="3">
</td>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td height="12" width="100%" style="color: #c09853;"></td>
</tr>
<tr>
<td width="100%">
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="4" height="20" width="100%">
<table width="100%" cellspacing="1" cellpadding="3">
<tbody>
<tr height="25">
<th width="150" align="left">First name:</th>
<td>First name..</td>
</tr>
<tr height="25">
<th width="150" align="left">Second:</th>
<td>Second name..</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td colspan="4">
<table width="100%" cellspacing="1" cellpadding="3" border="0" bgcolor="#929699">
<tbody>
<tr height="30" align="center" bgcolor="#e0e0e0">
<th class="text-center" width="5%">No.</th>
<th class="text-center" width="12%">Date</th>
<th class="text-center" width="8%">Time</th>
<th class="text-center" width="8%">Area</th>
<th class="text-center" width="22%">Status</th>
<th class="text-center" width="19%">Status(KOR)</th>
<th class="text-center" width="30%">Remarks</th>
<!-- 2018.01.22 이승민-------------------------------------- -->
<!-- ---------------------------------------------------- -->
</tr>
<tr height="50" bgcolor="#FFFFFF" align="center">
<td style="font-size: 100%;">1</td>
<td>2021.03.22</td>
<td>10:22</td>
<td>Korea</td>
<td>Oks</td>
<td>Test</td>
<td>Some new info</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
koteesy commented
Hello :d
Any updates?
zhengchun commented
Fixed. you can checkout the latest of xpath package to fix this.
koteesy commented
Fixed. you can checkout the latest of xpath package to fix this.
Thank you so much! I will check it.
koteesy commented
Look's like everything working fine. Thanks you!