gpt4 book ai didi

vba - MSHTML:CreateDocumentFromString 而不是 CreateDocumentFromUrl

转载 作者:行者123 更新时间:2023-12-03 15:12:48 25 4
gpt4 key购买 nike

我想使用 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'
....

最佳答案

你可以;

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

关于vba - MSHTML:CreateDocumentFromString 而不是 CreateDocumentFromUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9995257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com