.html文件没法解析,HTML解析 - 从.html文件
這似乎為我工作(采取了一些試驗和錯誤的)
@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2')
import org.ccil.cowan.tagsoup.*
import groovy.xml.*
String htmlTxt = """
Select
Male
Female
"""
// Define our TagSoup backed parser
def slurper = new XmlSlurper(new Parser())
// Parse our html
def h = slurper.parseText(htmlTxt)
// Find the input with the id 'txtName'
def i = h.body.input.list().find { [email?protected] == 'txtName' }
// Change it's value
[email?protected] = 'new value'
// Write it out (into a StringWriter for now)
def w = new StringWriter()
w << new StreamingMarkupBuilder().bind {
// Required to avoid the html: namespace on every node
mkp.declareNamespace '':'http://www.w3.org/1999/xhtml'
mkp.yield h
}
// XmlUtil.serialize neatens up our resultant xml -- but adds an xml declaration :-(
println new XmlUtil().serialize(w.toString())
[編輯]
那g ives結果:
Select
Male
Female
總結
以上是生活随笔為你收集整理的.html文件没法解析,HTML解析 - 从.html文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle数据库逻辑存储结构管理相关问
- 下一篇: led拼接屏报价_液晶拼接屏与led显示