Jsoup: get all heading tags

前端 未结 3 1355
野趣味
野趣味 2021-01-04 12:01

I\'m trying to parse an html document with Jsoup to get all heading tags. In addition I need to group the heading tags as [h1] [h2] etc...

     hh = doc.sel         


        
3条回答
  •  旧时难觅i
    2021-01-04 12:34

    Here is a Scala version of the answer that uses Ammonite's syntax to specify the Maven coordinates for Jsoup:

    import $ivy.`org.jsoup:jsoup:1.11.3`
    val html = scala.io.Source.fromURL("https://scalacourses.com").mkString
    val doc = org.jsoup.Jsoup.parse(html)
    doc.select("h1, h2, h3, h4, h5, h6, h7").eachText()
    

提交回复
热议问题