【问题标题】:Entering user and password in web generates error 462 remote server machine not found在 Web 中输入用户名和密码生成错误 462 找不​​到远程服务器机器
【发布时间】:2021-02-13 07:43:47
【问题描述】:

我想连接到要求输入用户名和密码的网页。

我需要一个宏

  • 输入用户名和密码并点击进入第一个网页。
  • 导航到包含我需要的数据的第二页。

代码没有填写用户和密码点击。我得到一个错误 462 找不​​到远程服务器机器。

Sub ExtractActivo()

Dim IE As Object
Dim pagina1 As HTMLDocument
Dim pagina2 As HTMLDocument

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

‘First page
IE.navigate "https://www.activobank.com/cs/Satellite/BC/"
Application.Wait (Now + TimeValue("00:00:02"))
Set pagina1 = IE.document
pagina1.getElementById("userDNI").Value = Range("M1").Value
Application.Wait (Now + TimeValue("0:00:02"))
pagina1.getElementById("pinNif").Value = Range("M2").Value
Application.Wait (Now + TimeValue("0:00:02"))
pagina1.getElementsByClassName("btn tipo4")(0).Click
Application.Wait (Now + TimeValue("00:00:02"))

‘Second page
IE.navigate "https://www.activobank.com/activobank/CUGlobalPositionNew.init.bs"

Set pagina2 = IE.document

'Here code to download tables

IE.Quit

Set IE = Nothing: Set pagina1 = Nothing: Set pagina2 = Nothing

End Sub

第二页的HTML

<!-- /1. Ahorro Inversión -->         
<!-- ELEMENTOS DEL BLOQUE -->
<table border="0" width="494" cellpadding="0" cellspacing="1" bgcolor="white" style="margin-bottom:10px">
<tr  class=apartado >
<td width="20" class="a12" height="10" align="right">
<a href='javascript:plegarDesplegar("1","CC");' >
<img id="_CC" src="/neti/images/AB/expandir.gif" border="0">
</a>
</td>
<td class="a12" width="354" height="15" valign="center" align="left"><b>&nbsp;Cuentas a la vista
</b>
</td>
<td width="120" height="15" valign="center" align="right">
<!-- MILLORA -->
<span class="a12b">999,99
&euro;
</span>
</td>
</tr>
</table>

<div id="_CC0" style="display:none">
<table border="0" width="494" cellpadding="0" cellspacing="0" bgcolor="white">
<!-- JV-18725 Añadimos CI -->
<tr class="fila1">
<!--  Boton edicion cuenta -->
<td class="a11" width="195" height="15" align="left" valign="top" nowrap>
<table class="septd2">
<tr>
<td style="padding-left:20px" valign="center" align="left" width="10">
<a href='javascript:mostrarEdicion("_CC0");' >
<img id="_BtEdicion__CC0" name="_BtEdicion" src="/neti/images/AB/Lapiz-11x11.png" border=0>
</a>
</td>
<td align="left" class="a11">
<div id="_CC0_CC">
CUENTA ACTIVA
</div>
<div id="_CC0_M" style="display:none;">
<span class="returnicon">
<script>
function validate_CC0(){
var valueInput = document.getElementById("_CC0_IN").value;
valueInput = valueInput.replace(/[^A-Za-z0-9\u002e\s\u002c\u003a\u003b\u003f\u0021\u002d\u005f\u00A1\u00BF\u002D\u00E4\u00E1\u00E0\u00E7\u00EB\u00E9\u00E8\u00ED\u00EC\u00EF\u00F1\u00F6\u00F3\u00F2\u00FA\u00F9\u00FC\u00C4\u00C1\u00C0\u00C7\u00CB\u00C9\u00C8\u00CD\u00CC\u00CF\u00D1\u00D3\u00D2\u00D6\u00DA\u00D9\u00DC\u00A1\u00BF]/g,"");
document.getElementById("_CC0_IN").value = valueInput;
document.getElementById("_CC0_CC").innerHTML = valueInput;
}
</script>
<input id="_CC0_IN" type="text" maxlength="25" onblur='validate_CC0();timeNameAccountAuto("/activobank/","_CC0_IN","xxxxx","CUENTA ACTIVA","2","La descripción debe contener como mínimo 3 caracteres","La descripción debe contener como máximo 25 caracteres");' onkeydown='return validateExit(event)' onKeyPress='validate_CC0();return validateKeyPress(event,"xxxxxxx","/activobank/","La descripción debe contener como mínimo 3 caracteres","2","CUENTA ACTIVA","La descripción debe contener como máximo 25 caracteres")'/>
<a href='javascript:getNameAccount("_CC0","xxxxx","/activobank/","CUENTA ACTIVA","2");' >
<img src="/neti/images/AB/Borrar-9x9.png" border=0 >
</a>
</span>
</div>
</td>
</tr>
<tr>
<td style="padding-left:20px" valign="center" align="left" width="10">&nbsp;</td>
<td class="a11" width="230" height="15" align="left" valign="center" colspan="2">
<input type="hidden" value="" name="alias_cc_2">

【问题讨论】:

    标签: excel vba authentication web-scraping passwords


    【解决方案1】:

    以下针对正确的元素并点击提交。它使用 [] attribute = value css 选择器和#id 选择器。

    Option Explicit   
    'VBE > Tools > References:
    ' Microsoft Internet Controls
    Public Sub Login()
        Dim ie As InternetExplorer
        Set ie = New InternetExplorer
    
        With ie
            .Visible = True
            .Navigate2 "https://www.activobank.com/cs/Satellite/BC/"
    
            While .Busy Or .readyState < 4: DoEvents: Wend
    
            .document.querySelector("[name=userDNI]").Value = "abc"
            .document.querySelector("[name=pinDNI]").Value = "123"
            .document.querySelector("#button1").Click
    
            While .Busy Or .readyState < 4: DoEvents: Wend
    
            Stop
    
        End With
    End Sub
    

    【讨论】:

    • 完美运行。在第一页登录,然后导航到第二页。进入第二页后,我需要将银行账户中的余额从该页复制到 Excel。该余额在我想完整复制的表格中,如果不可能,至少复制我添加到原始问题中的 html 代码的值 999.99。我应该在代码中添加什么来做到这一点?
    • 我建议您考虑接受此答案并在下一部分中打开一个新问题,并确保包含 html,因为我们无法登录并查看该页面。您可以使用通过编辑提供的 sn-p 工具来添加 html。不要插入html的图片。
    • 对不起,我会的。
    • 抱歉,我该如何接受您的回答?我不知道该怎么做。
    • 你点击答案旁边的复选标记stackoverflow.com/help/someone-answers
    【解决方案2】:

    您的字段/类名称来自“Activo Online”选项卡,但“首页”的 URL 默认为“详细信息”选项卡。您可能需要使用“详细信息”上的登录字段或先导航到“Activo Online”。

    https://www.activobank.com/cs/Satellite/BC/Activo-Online/1191355337777/es/ 似乎是指向包含您尝试使用的字段的页面的直接链接。

    您可能还需要在每个循环之后:

    IE.navigate 
    

    等待页面加载。所以在下面添加这段代码:

    Do While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
    

    这应该意味着您可以摆脱“application.wait”行。

    【讨论】:

      【解决方案3】:

      我认为您没有单击正确的按钮。转到您链接的页面并检查登录按钮不会向我显示“btn typo4”的元素,但是:

      <input id="button1" name="accept" type="button" value="Entrar" onclick="return validate()" class="btn login" tabindex="3" style="color: rgb(255, 255, 255);">
      

      当他有一个 inputId 时,你为什么尝试通过类名来定位按钮?

      奖金:https://codingislove.com/http-requests-excel-vba/

      xmlhttp 请求更适合使用 vba 进行网页抓取。

      如果我错了,请随时删除。

      【讨论】:

        猜你喜欢
        • 2021-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-01
        • 1970-01-01
        • 2017-11-07
        • 2015-06-28
        • 1970-01-01
        相关资源
        最近更新 更多