VBScript:从网页下载 JSON 文件并将内容读取到变量
VBScript: Download JSON File From Webpage and Read Contents to Variable
我正在尝试编写一个 VB 脚本来登录到一个安全网站并下载一系列报告。
下面让我进入网站,但登录后整个网站都写在 javascript。
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Visible = True
.Navigate SecureWebsite
Do While .Busy Or Not .readyState = 4: WScript.Sleep 100: Loop
Do Until .document.readyState = "complete": WScript.Sleep 100: Loop
Do While TypeName(.document.getElementById("username")) = "Null": WScript.Sleep 100: Loop
End With
Set Helem = oIE.document.getElementByID("username")
Helem.Value = "myusername"
Set Helem = oIE.document.getElementByID("password")
Helem.Value = "mypassword"
Call oIE.Document.all.loginForm.submit
我找到了一个 link,我可以使用它和参数来搜索我需要的报告。当我按照 link 时,Internet Explorer returns 一个 JSON 文件,我可以 open/download。 JSON 文件包含一个报告 ID,我可以将其用作另一个 link 中的参数来下载我需要的文件。
有没有什么方法可以使用 InternetExplorer 对象将 JSON 文件的文本内容读取到一个变量中,以便我可以从中解析出报告 ID?我发现的所有示例都使用了 MSXML2.XMLHTTP 对象,但这会断开它与我在 InternetExplorer 对象中实现的登录的连接。
我最终在 C# 中完成了这项工作。该网站有重定向和 SSO,所以我无法获得直接的 WebClient Get/Post,但我通过使用 WebBrowser 对象登录然后将 cookie 传递给 HttpWebRequest 对象来妥协,根据这个优秀的指南:
https://www.codeproject.com/Tips/659004/Download-of-file-with-open-save-dialog-box
我正在尝试编写一个 VB 脚本来登录到一个安全网站并下载一系列报告。
下面让我进入网站,但登录后整个网站都写在 javascript。
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Visible = True
.Navigate SecureWebsite
Do While .Busy Or Not .readyState = 4: WScript.Sleep 100: Loop
Do Until .document.readyState = "complete": WScript.Sleep 100: Loop
Do While TypeName(.document.getElementById("username")) = "Null": WScript.Sleep 100: Loop
End With
Set Helem = oIE.document.getElementByID("username")
Helem.Value = "myusername"
Set Helem = oIE.document.getElementByID("password")
Helem.Value = "mypassword"
Call oIE.Document.all.loginForm.submit
我找到了一个 link,我可以使用它和参数来搜索我需要的报告。当我按照 link 时,Internet Explorer returns 一个 JSON 文件,我可以 open/download。 JSON 文件包含一个报告 ID,我可以将其用作另一个 link 中的参数来下载我需要的文件。
有没有什么方法可以使用 InternetExplorer 对象将 JSON 文件的文本内容读取到一个变量中,以便我可以从中解析出报告 ID?我发现的所有示例都使用了 MSXML2.XMLHTTP 对象,但这会断开它与我在 InternetExplorer 对象中实现的登录的连接。
我最终在 C# 中完成了这项工作。该网站有重定向和 SSO,所以我无法获得直接的 WebClient Get/Post,但我通过使用 WebBrowser 对象登录然后将 cookie 传递给 HttpWebRequest 对象来妥协,根据这个优秀的指南:
https://www.codeproject.com/Tips/659004/Download-of-file-with-open-save-dialog-box