简体   繁体   English

使用登录名和密码的VBA Web查询

[英]VBA Web query with login+password

Morning guys, 早上好,

Using already answered questions on here i am still unable to get any code to work for my particular site, unfortunately as it is an internal website i cannot share the actual site. 使用此处已回答的问题,我仍然无法为我的特定网站获得任何代码,但是很遗憾,因为它是内部网站,所以我无法共享实际的网站。

The site is a .jsp login page could this be causing the issue? 该站点是.jsp登录页面,这可能是导致此问题的原因吗? The macro opens the login page in IE but doesn't enter any user data into the fields or submit currently. 宏会在IE中打开登录页面,但不会在字段中输入任何用户数据或当前未提交。

I also get error message "the object invoked has disconnected from it's clients" once the macro is running. 宏运行后,我还会收到错误消息“被调用的对象已与其客户端断开连接”。

Microsoft internet controls is active and Forms 2.0 is active in references also Microsoft Internet控件处于活动状态,Forms 2.0在引用中也处于活动状态

I am fairly new to VBA to if i am missing anything obvious please let me know, i have lowered security settings within IE also. 我对VBA还是比较陌生,如果我缺少任何明显的内容,请告诉我,我也降低了IE中的安全设置。

EDIT I am somewhat sure this is to do with my form ID's but i can't see where i went wrong? 编辑我可以肯定这与我的表单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

Page Source: 页面来源:

<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>

I used the following in something similar: 我在类似的内容中使用了以下内容:

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

It will display a messagebox which asks you to sign in if you land on the loginpage. 它将显示一个消息框,询问您是否登陆登录页面。 Then you manually log in and start the script again. 然后,您手动登录并再次启动脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM