登录网站登录和密码

时间:2013-10-10 14:19:14

标签: vbscript

我尝试创建一个自动启动网站的VBS脚本。这部分我可以解决。 但是现在我需要把这个函数登录为 这就是我坚持不懈的观点。

所以我希望你能帮助我。 这是我打开网站的脚本

Dim objExplorer


 Set objExplorer = WScript.CreateObject("InternetExplorer.Application")

 Do While (objExplorer.Busy)
 Wscript.Sleep 250
 Loop

 objExplorer.TheaterMode = False
 objExplorer.AddressBar = True
 objExplorer.MenuBar = True
 objExplorer.StatusBar = True
 objExplorer.ToolBar = False
 objExplorer.Resizable = True


 objExplorer.Height = 600
 objExplorer.Width = 800
 objExplorer.Left = 0
 objExplorer.Top = 0
 ' objExplorer.FullScreen = True
 objExplorer.Silent = False
 objExplorer.Visible = True


 objExplorer.Navigate https://mi-xxxxx-xxx-xxxxx.xxx.com/xxxxxxxxxxxxx/login.aspx

objExplorer.Login = User
ObjExplorer.Password = Password

 wscript.sleep 6000

Set objShell = CreateObject("Wscript.Shell")
 objShell.Run("taskkill /F /IM iexplore.exe /T")

 Set objExplorer = nothing

我希望有一种简单的方法可以得出结果。

非常感谢您在这种情况下的帮助。 最好的祝福 马丁

2 个答案:

答案 0 :(得分:2)

尝试使用Fiddler之类的内容检查登录过程,而不是尝试通过GUI自动登录。这应该给你实际的请求,将凭证从客户端传递到服务器。有了这些信息,您可以使用XMLHttpRequest自动登录:

url = "https://mi-xxxxx-xxx-xxxxx.xxx.com/xxxxxxxxxxxxx/login.asp"

user = "..."
pass = "..."
credentials = "username=" & user & "&password=" & pass

Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "POST", url, False
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.send credentials

If req.status = 200 Then
  'login successful
Else
  'login failed
End If

您可能需要根据Fiddler透露的内容调整urlcredentials字符串。您可能还需要使用以下内容对用户名和/或密码进行编码:

Function Encode(ByVal str)
  Set re = New RegExp
  re.Pattern = "[^a-zA-Z0-9_.~-]"

  enc = ""
  For i = 1 To Len(str)
    c = Mid(str, i, 1)
    If re.Test(c) Then c = "%" & Right("0" & Hex(Asc(c)), 2)
    enc = enc & c
  Next

  Encode = enc
End Function

答案 1 :(得分:0)

我找到了一个很好的方法来获得结果。

WScript.Sleep 5000
WshShell.SendKeys "******"
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WScript.Sleep 3000
WshShell.SendKeys "*********"
WshShell.SendKeys "{TAB}"
WScript.Sleep 3000
WshShell.SendKeys "{ENTER}"

wscript.sleep 10000

所以这个任务就解决了。 非常感谢您的所有命令。 最好的祝福 马丁

相关问题