使用 vbscript 读取/保存网页 [英] using vbscript to read / save a webpage
问题描述
目标:登录网页并将 html 保存到文件中以供稍后解析.
goal: log into the web page and save the html to a file for parsing later.
页面上的 html 只是一个用户列表以及他们登录和注销的时间.
the html on the page is just a list of users and when they logged in and off.
当您加载网页时,会弹出一个 javascript 框并询问登录信息
When you load the web page up a javascript box pops up and asks for login information
我可以用 SendKeys 填充它,但我真的想在不弹出窗口的情况下做到这一点
i can fill this with SendKeys but i really want to do this without a window popping up
Set IE = CreateObject("InternetExplorer.Application")
set WshShell = CreateObject("WScript.Shell")
IE.Visible = False ' doesn't set IE page as invisible?????
IE.Navigate "https://mysite/site/console/client-log.jsp"
'how do i fill in the box ???
推荐答案
我建议使用类似 Fiddler 的东西 标识进行实际登录的请求,然后在 XMLHttpRequest.
I'd suggest to use something like Fiddler to identify the request that does the actual login, and then use that information in an XMLHttpRequest.
url = "..."
filename = "..."
Set req = CreateObject("MSXML2.XMLHTTP.6.0")
req.open "POST", url, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send "field1=foo&field2=bar&..."
Set fso = CreateObject("Scripting.FileSystemObject")
fso.OpenTextFile(filename, 2, True).WriteLine req.responseText
如果响应是 UTF-8 编码,您可能需要使用 ADODB.Stream 用于保存内容的对象.
If the response is UTF-8 encoded you may need to use an ADODB.Stream object for saving the content.
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 'text
stream.Position = 0
stream.Charset = "utf-8"
stream.WriteText req.responseText
stream.SaveToFile filename, 2
stream.Close
这篇关于使用 vbscript 读取/保存网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!