Scala and HTML parsing

后端 未结 5 2325
北海茫月
北海茫月 2020-12-14 08:53

How do you load an HTML DOM document into Scala? The XML singleton had errors when trying to load the xmlns tags.

import java.net._
import java.io._
import s         


        
5条回答
  •  抹茶落季
    2020-12-14 09:05

    I have just tried to use this answer with scala 2.8.1 and ended up using the work from:

    http://www.hars.de/2009/01/html-as-xml-in-scala.html

    The interesting bit that I needed was:

    val parserFactory = new org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl
    val parser = parserFactory.newSAXParser()
    val source = new org.xml.sax.InputSource("http://www.scala-lang.org")
    val adapter = new scala.xml.parsing.NoBindingFactoryAdapter
    adapter.loadXML(source, parser)
    

提交回复
热议问题