Ji icon indicating copy to clipboard operation
Ji copied to clipboard

XPath error : Invalid expression

Open huhuegg opened this issue 6 years ago • 2 comments

我之前用的是Kanna,运行都正常,但是有少许内存泄漏。 换Ji库后,macOS下运行很完美,但是相同代码到Linux上所有XPath都会报错。 XPath error : Invalid expression

huhuegg avatar May 18 '18 09:05 huhuegg

@huhuegg 可以把code snippet贴出来吗?或者你的xpath是什么?

honghaoz avatar May 22 '18 20:05 honghaoz

func testXPath() {
    HttpHandler.doGetRequest(urlStr: "http://www.luoxia.com/fanghua/69911.htm") { (data) in
        guard let data = data else {
            print("Http request failed")
            return
        }
        guard let doc = Ji(htmlData: data, encoding: .utf8) else {
            print("Ji init failed")
            return
        }
        
        let listXpath = "//*[@id='pagewrap']/article"
        guard let rootNode = doc.xPath(listXpath)?.first else {
            print("listXpath not found!(\(listXpath))")
            return
        }
        print(rootNode.content)
    }
}

操作系统: ubuntu16.04 swift: 4.1 Ji: .package(url: "https://github.com/honghaoz/Ji.git", from: "2.1.0") error:

XPath error : Invalid predicate
XPath error : Invalid expression
listXpath not found!(//*[@id='pagewrap']/article)

huhuegg avatar May 23 '18 03:05 huhuegg