using vbscript to read / save a webpage

前端 未结 1 885
刺人心
刺人心 2021-01-21 21:49

goal: log into the web page and save the html to a file for parsing later.

the html on the page is just a list of users and when they logged in and off.

When yo

1条回答
  •  粉色の甜心
    2021-01-21 22:34

    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
    

    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
    

    0 讨论(0)
提交回复
热议问题