在 VBA Excel 中读取 HTML 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14103220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:01:33  来源:igfitidea点击:

Reading HTML file in VBA Excel

vba

提问by Alpan67

i want to read the HTML code in VBA (something like URL in Java). I need to save it in a string. I parse it afterwards.

我想阅读 VBA 中的 HTML 代码(类似于 Java 中的 URL)。我需要将它保存在一个字符串中。我后来解析了。

alpan67

alpan67

回答by Daniel

Here's a function for you. It will return the String of the HTML returned by a given URL.

这里有一个功能给你。它将返回给定 URL 返回的 HTML 字符串。

Function GetHTML(URL As String) As String
    Dim HTML As String
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", URL, False
        .Send
        GetHTML = .ResponseText
    End With
End Function

Just make sure your provided URL is well formed. I.E. it includes the http://or https://if appropriate.

只需确保您提供的 URL 格式正确。IE 它包括http://https://如果合适。

For Example: GetHtml("www.google.com")is incorrect.
You would want GetHtml("https://www.google.com/")

例如:GetHtml("www.google.com")不正确。
你会想要GetHtml("https://www.google.com/")

回答by bonCodigo