在Web中输入用户和密码会生成错误462找不到远程服务器计算机

问题描述 投票:1回答:3

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

我需要一个宏

  • 输入用户和密码,然后按“确定”进入第一个网页。
  • 导航到第二页,其中包含我需要的数据。

代码不会填写用户和密码并单击。我找不到错误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
3个回答
0
投票

以下针对正确的元素和点击提交。它使用[] 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

0
投票

我想你没有点击右键。转到您链接的页面,并检查登录按钮不会显示“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/

xmlhttprequest更适合使用vba进行网页抓取。

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


0
投票

您的字段/类名称来自“Activo Online”选项卡,但“First Page”的URL默认为“Particulares”选项卡。您可能需要使用“Particulares”上的登录字段或首先导航到“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'行。

© www.soinside.com 2019 - 2024. All rights reserved.