Convert xPath to JSoup query

前端 未结 6 1472
南旧
南旧 2020-12-09 10:29

Does anyone know of an xPath to JSoup convertor? I get the following xPath from Chrome:

 //*[@id=\"docs\"]/div[1]/h4/a

and would like to c

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 10:58

    I have tested the following XPath and Jsoup, it works.

    example 1:

    [XPath]

    //*[@id="docs"]/div[1]/h4/a
    

    [JSoup]

    document.select("#docs > div > h4 > a").attr("href");
    

    example 2:

    [XPath]

    //*[@id="action-bar-container"]/div/div[2]/a[2]
    

    [JSoup]

    document.select("#action-bar-container > div > div:eq(1) > a:eq(1)").attr("href"); 
    

提交回复
热议问题