Comments (8)
@jcamiel , I updated xpath package to fix this issue. Trying get the latest version of xpath package to solve.
from htmlquery.
Hi,
Thanks you for this really quick fix !
I've tested it and it's ok. Unfortunately, while I tried to debug it, I've found another possible issue (maybe related to the previous?):
<html>
<body>
<div class="fruit">Apple</div>
<div class="color">Red</div>
</body>
</html>
In this case, the following path string((//div[@class="color"])[1])
should return 'Red' (if I'm not mistaken). I've tested this one with your recent fix but it doesn't seem to work.
html := `<html>
<body>
<div class="fruit">Apple</div>
<div class="color">Red</div>
</body>
</html>`
doc, _ := htmlquery.Parse(strings.NewReader(html))
test1 := `string((//div[@class="color"])[1])`
expr1, _ := xpath.Compile(test1)
v1 := expr1.Evaluate(htmlquery.CreateXPathNavigator(doc))
// v1 = "", should be Red ?
Regards,
jc
from htmlquery.
yes, should be Red
. This bug still exist :(
from htmlquery.
@jcamiel , try again.
html := `<html><body>
<div class="fruit">Apple</div>
<div class="color">Red</div>
<div>
<div class="fruit">Pear</div>
<div class="fruit">Orange</div>
</div>
</body></html>`
doc, _ := htmlquery.Parse(strings.NewReader(html))
testPath := `//div[@class="color"][1]`
node := htmlquery.FindOne(doc, testPath)
fmt.Println(htmlquery.InnerText(node))
// Output: Red
testPath = `//div[@class="fruit"][1]`
node = htmlquery.FindOne(doc, testPath)
fmt.Println(htmlquery.InnerText(node))
// Output: Apple
testPath = `//div[1]`
for _, node := range htmlquery.Find(doc, testPath) {
fmt.Println(htmlquery.InnerText(node))
// Apple
// Orange
}
testPath = `//div[2]`
for _, node := range htmlquery.Find(doc, testPath) {
fmt.Println(htmlquery.InnerText(node))
// Red
// Pear
}
from htmlquery.
Hi @zhengchun
I've tested your last commit and it's ok but now I've still have another problem :( ! Maybe related still related to the [%n] operator I don't know :
func TestEvalXPathHTML(t *testing.T) {
html := `<html><body>
<div class="fruit">
<div class="color">Red</div>
</div>
<div class="fruit">
<div class="color">Yellow</div>
</div>
</body></html>`
doc, _ := htmlquery.Parse(strings.NewReader(html))
test := `count((//div[@class="fruit"])[1]//div[@class="color"])`
expr, _ := xpath.Compile(test)
v := expr.Evaluate(htmlquery.CreateXPathNavigator(doc))
// v = 2, expected v = 1
}
I really appreciate your fixing and hope you don't mind me sending your this stuff. I've
a whole html page that I'm trying to analyse for my work and I try to isolate to a minimal sample the
xpath queries I think are not ok,
Regards,
Jc
from htmlquery.
I have trying [n]
but found it is difficult. I can solved your //div[@class="fruit"])[1]//div[@class="color"])
but can't solve below example.
html := `<html><body>
<div class="fruit">Apple</div>
<div class="color">Red</div>
<div>
<div class="fruit">Pear</div>
<div class="fruit">Orange</div>
</div>
<div class="fruit">Peach</div>
</body></html>`
testPath := `//div[@class="fruit"][2]`
I have marked this issue.
from htmlquery.
Ok thank you very much, let me know if you have some code to test, I'll test it with my page,
Best regards,
Jc
from htmlquery.
fixed on [email protected]
from htmlquery.
Related Issues (20)
- Access inner text from node with other elements around HOT 2
- [bug] htmlquery.QueryAll not returning all node attribute results HOT 2
- Randomly panics ! HOT 1
- `replace()` on a query doesn't seem to work HOT 3
- `Find` returns an element when passed an invalid xpath HOT 3
- Get a panic when parse html page HOT 6
- Xpath failing to find nodes HOT 2
- FindOne with expression containing groups only works the first time HOT 2
- go: github.com/antchfx/htmlquery: invalid github.com import path "github.com/antchfx" HOT 4
- concurrent writes to map panic HOT 2
- `LoadURL()` supports 'gzip ', 'deflate' decompression
- Duration of the request HOT 1
- Which package would be faster htmlquery or xmlquery? HOT 1
- panic: not yet support this function lower-case() HOT 2
- html data miss
- Can,t Get Scripts useing xpath expression
- i can,t parse scripts from document , using xpath query HOT 2
- add function to set the default http request cilent HOT 1
- Question: How I can remove specific child from parent so when I do InnerText I don't get the text of the child HOT 1
- can not get element in noscript tag HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from htmlquery.