在 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
Reading HTML file in VBA Excel
提问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
To do the URL DECODINGyou may use that post as a reference.
Here goes a article that uses MS Word to save html of web page as text.
Code in Excel VBA - from VBAExpress: I wouldn't fancy copying his code. You may give it a try and comment.
要进行URL 解码,您可以使用该帖子作为参考。
Excel VBA 中的代码 -来自 VBAExpress:我不想复制他的代码。您可以尝试一下并发表评论。