Skip to content
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

Node xpath behaviour is wrong #18

Closed
cocoBavan opened this issue Jul 9, 2015 · 1 comment
Closed

Node xpath behaviour is wrong #18

cocoBavan opened this issue Jul 9, 2015 · 1 comment

Comments

@cocoBavan
Copy link

When you change the sample HTML to have 2 box classes,

...... " <div class='box'>" + " <span class='dat'>" + " <strong content='2014-12-31'>2014/12/31</strong>" + " </span>" + " <h2>Hoge</h2>" + " </div>" + " <div class='box'>" + " <span class='dat'>" + " <strong content='2014-12-31'>2014/12/31</strong>" + " </span>" + " <h2>SecondHoge</h2>" + " </div>" ......

and then when you run

if let path = bodyNode?.xpath("//div[@class='box']") { for node in path { println("fancy node \(node.tagName)") println(node.xpath("//h2")?.count) } }

it returns

fancy node div
Optional(2)
fancy node div
Optional(2)

as answer, which I think is wrong and should return 1 & 1.

@cocoBavan cocoBavan changed the title Node behaviour is wrong Node xpath behaviour is wrong Jul 9, 2015
@tid-kijyun
Copy link
Owner

fixed @8c8ebbc

Please correct:

if let path = bodyNode?.xpath("//div[@class='box']") {
    for node in path {
        println("fancy node \(node.tagName)")
        println(node.xpath(".//h2")?.count)     //=> Change "//h2" to ".//h2"
    }
}

thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants