Does jsoup support xpath?

后端 未结 3 1634
迷失自我
迷失自我 2020-12-08 19:24

There\'s some work in progress related to adding xpath support to jsoup https://github.com/jhy/jsoup/pull/80.

  • Is it working?
  • How can I use it?
3条回答
  •  囚心锁ツ
    2020-12-08 19:57

    Not yet,but the project JsoupXpath has make it.For example,

    String html = "
    some body
    Two
    "; JXDocument underTest = JXDocument.create(html); String xpath = "//div[contains(@class,'xiao')]/text()"; JXNode node = underTest.selNOne(xpath); Assert.assertEquals("Two",node.asString());

    By the way,it supports the complete W3C XPATH 1.0 standard syntax.Such as

    //ul[@class='subject-list']/li[./div/div/span[@class='pl']/num()>(1000+90*(2*50))][last()][1]/div/h2/allText()
    //ul[@class='subject-list']/li[not(contains(self::li/div/div/span[@class='pl']//text(),'14582'))]/div/h2//text()
    

提交回复
热议问题