0

各位早安

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

该站点是一个 .jsp 登录页面,这会导致问题吗?该宏在 IE 中打开登录页面,但当前未在字段中输入任何用户数据或提交。

一旦宏运行,我还会收到错误消息“调用的对象已与其客户端断开连接”。

Microsoft Internet 控件处于活动状态,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>
4

1 回答 1

1

我在类似的东西中使用了以下内容:

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

如果您登陆登录页面,它将显示一个消息框,要求您登录。然后您手动登录并再次启动脚本。

于 2017-03-08T12:33:06.237 回答