【发布时间】:2019-04-07 13:13:04
【问题描述】:
我有两个代码..应该将 html 文件导出到文本文件
Sub Demo1()
Dim http As New XMLHTTP60
Dim html As New HTMLDocument
With http
.Open "GET", "https://www.google.com.eg/", False
.send
html.body.innerHTML = .responseText
WriteTxtFile html.body.innerHTML
End With
End Sub
Sub WriteTxtFile(ByVal aString As String, Optional ByVal filePath As String = "C:\Users\Future\Desktop\Output.txt")
Dim fso As Object
Dim fileout As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileout = fso.CreateTextFile(filePath, True, True)
fileout.write aString
fileout.Close
End Sub
Sub Demo2()
Dim ie As Object
Dim f As Integer
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.navigate ("https://www.google.com.eg/")
Do: DoEvents: Loop Until .readyState = 4
f = FreeFile()
Open ThisWorkbook.Path & "\Sample.txt" For Output As #f
Print #f, .document.body.innerHTML
Close #f
.Quit
End With
End Sub
Demo1 和 Demo2 都是代码 .. 它们导致“Sample.txt”和“Output.txt” 但是我发现那些 html 文档是不同的结果 你能帮我澄清一下什么是正确的......以及为什么它们不同?
感谢您的帮助
【问题讨论】:
-
它们有何不同?
-
脚本在浏览器中加载后可以更改/添加到页面内容。这不会发生在 xmlhttp
标签: excel vba xmlhttprequest