mwo*_*e02 4 vb6 vba mshtml html-parsing
我想使用MSHTML库来解析我在字符串变量中的一些HTML.但是,我无法弄清楚如何做到这一点.我可以轻松地解析给定已知URL的网页内容,但不能直接解析源HTML.这可能吗?如果是这样,怎么样?
Public Sub ParseHTML(sHTML As String)
Dim oHTML As New HTMLDocument, oDoc As HTMLDocument
'This works:'
Set oDoc = oHTML.createDocumentFromUrl("http://www.google.com", "")
'I would like to do the following but no such method actually exists:'
Set oDoc = oHTML.createDocumentFromString(sHTML)
....
'Parse the HTML using the oDoc variable'
....
Run Code Online (Sandbox Code Playgroud)
Ale*_* K. 14
您可以;
Dim odoc As Object
Set odoc = CreateObject("htmlfile") '// late binding
'// or:
'// Set odoc = New HTMLDocument
'// for early binding
odoc.open
odoc.write "<p> In his house at R'lyeh, dead <b>Cthulhu</b> waits dreaming</p>"
odoc.Close
MsgBox odoc.body.outerHTML
Run Code Online (Sandbox Code Playgroud)