How to create a Jsoup.select.Elements with duplicate data?

后端 未结 2 1591
猫巷女王i
猫巷女王i 2021-01-23 02:17

I have a web-page:



        
2条回答
  •  情歌与酒
    2021-01-23 02:54

    It seems you have hit a known issue from Jsoup (see luksch's answer for details). However, here is a workaround working on Jsoup 1.8.3.

    table#timetable > tbody > tr > td.time
    

    SAMPLE CODE

    String html = "\n\n    \n      \n      \n      \n      \n      \n    \n\n
    \n
    10:30 12:05
    \n
    \n
    12:30 14:05
    \n
    \n
    12:30 14:05
    \n
    \n
    14:30 16:05
    \n
    \n
    16:30 18:05
    \n
    "; Document doc = Jsoup.parse(html); for (Element elt : doc.select("table#timetable > tbody > tr > td.time")) { System.out.println(elt.text()); }

    OUTPUT

    10:30 12:05
    12:30 14:05
    12:30 14:05
    14:30 16:05
    16:30 18:05
    

    Tested on Jsoup 1.8.3

提交回复
热议问题