使用login名+密码的VBA Web查询

早上好,

使用已经在这里回答的问题,我仍然无法获得任何代码为我的特定网站工作,不幸的是,因为它是一个内部网站,我不能分享实际的网站。

该网站是一个.jsplogin页面可以导致这个问题? macros在IE中打开login页面,但不会将任何用户数据input到字段中或当前提交。

一旦macros运行,我也会收到错误消息“被调用的对象已经从它的客户端断开”。

微软的互联网控件是活跃的,并且Forms 2.0在参考中也是活跃的

我是相当新的VBA如果我错过任何明显的请让我知道,我已经降低了IE内的安全设置。

编辑我有点确定这是做我的表单ID,但我不明白我哪里出错了?

Sub GetTable() Dim ieApp As InternetExplorer Dim ieDoc As Object Dim ieTable As Object Dim clip As DataObject 'create a new instance of ie Set ieApp = New InternetExplorer 'you don't need this, but it's good for debugging ieApp.Visible = True 'assume we're not logged in and just go directly to the login page ieApp.Navigate "http://dss-gp-mida-002/MidasDS/login.jsp Do While ieApp.Busy: DoEvents: Loop Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop Set ieDoc = ieApp.Document 'fill in the login form – View Source from your browser to get the control names With ieDoc.forms(0) .Username.Value = "Carterr" .Password.Value = "password" .submit End With Do While ieApp.Busy: DoEvents: Loop Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop 'now that we're in, go to the page we want ieApp.Navigate "http://dss-gp-mida-002/MidasDS/homepage.jsp" Do While ieApp.Busy: DoEvents: Loop Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop 'get the table based on the table's id Set ieDoc = ieApp.Document Set ieTable = ieDoc.all.Item("sampletable") 'copy the tables html to the clipboard and paste to teh sheet If Not ieTable Is Nothing Then Set clip = New DataObject clip.SetText "" & ieTable.outerHTML & "" clip.PutInClipboard Sheet1.Select Sheet1.Range("A1").Select Sheet1.PasteSpecial "Unicode Text" End If 'close 'er up ieApp.Quit Set ieApp = Nothing End Sub 

页面来源:

 <input type="hidden" name="urlwanted" value=""><input type="hidden" name="sourcePageURL" value=""><input type="hidden" name="ssoiid" value=""> <div> <div class="form-group"> <label for="username">Username</label><input name="username" id="username" type="text" class="form-control" placeholder="Enter Username"> </div> <div class="form-group"> <label for="password">Password</label><input name="password" id="password" type="password" class="form-control" placeholder="Enter Password"> </div> <script> $("#username").keyup(function(event) { if (event.which == 13) { $("#loginform").submit(); } }); $("#password").keyup(function(event) { if (event.which == 13) { $("#loginform").submit(); } }); </script> <div class="form-group"> <div class="btn-group-vertical-justified"> <button name="login" type="button" value="Log In" class="btn btn-primary" onclick="document.loginform.ssoiid.value=&quot;&quot;;document.loginform.submit()">Log In</button> </div> 

我用了类似的东西:

 Set ie = GetIE("www.url.com") If Not ie is Nothing Then ie.navigate (strtarget) 'strtarget is the target url Do Until ie.ReadyState = 4: DoEvents: Loop If ie.LocationURL = "www.url.com/loginpage" Then MsgBox "Login Please!!" Else pageText = ie.document.body.innertext End if Else MsgBox "IE not found!!" End if 

它会显示一个消息框,要求您loginlogin页面。 然后您手动login并再次启动脚本。