使用vba复制到Excel从网页上的当前帐户余额

时间:2019-03-19 22:21:22

标签: excel vba web web-scraping

在论坛的帮助下,我创建了一个宏vba以连接到我的银行的网络,输入用户名和密码并正确登录。 使用vba宏登录后,我转到另一个页面,该页面是我的银行帐户余额,这些是我要复制到Excel的数据。我想要的数据是我在下面放置的html代码中所说的999.99的位置。

要执行此操作,我必须在vba代码中添加什么?

这是宏的代码。

'VBE > Tools > References:
' Microsoft Internet Controls
Public Sub SaldoActivo()
    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 = "123456789"
        .document.querySelector("[name=pinNif]").Value = "123456789"
        .document.querySelector("#button1").Click

        While .Busy Or .readyState < 4: DoEvents: Wend

       ‘ Navigate second page with 
        .Navigate2 "https://www.activobank.com/activobank/CUGlobalPositionNew.init.bs"

        While .Busy Or .readyState < 4: DoEvents: Wend

    End With

‘Here I need the code to copy the account balance data

ie.Quit
Set ie = Nothing

End Sub

这是用于复制帐户余额数据的代码

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

1 个答案:

答案 0 :(得分:0)

基于完整html

ie.document.getElementsByClassName("septd")(5).getElementsByTagName("span")(1).innerText

ie.document.getElementsByTagName("td")(39).innerText