我正试图从网页中获取某个值,但我尝试的所有内容都不起作用。我的HTML代码是:
<tr class="TRLinha1">
<td class="TDTitulo">Adv. Funcionário</td>
<td class="TDLinha2"><span id="C2">Fulano De tal </span></td>
<td class="TDTitulo">Adv. Credenciado</td>
<td class="TDLinha2"><span id="C3">Escritorio Identidade</span></td>
<td class="TDTitulo" colspan="2">
<img id="imgAdvogadoCredenciado" onclick="fcnShowAdvogadoCredenciado(1)" onmouseover="this.style.cursor='hand'" src="../../../../../../../Portal/Imagens/arquivo.png" alt="Exibir Advogado Credenciado" style="border-width:0px;">
</td>
我想要获得的价值是id =“C2” - &gt;弗拉诺德塔尔。然后我将在单元格中设置此值。我已经有了VBA代码来登录当前的网页。
任何人都可以帮助我吗?
这是我的VBA代码:
Sub FazerLoginSite()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
Dim node, nodeList
NumeroPasta = InputBox("Pasta")
With IE
.Visible = True
.Navigate ("https:mywebsite")
While .Busy Or .ReadyState <> 4: DoEvents: Wend
On Error Resume Next
.document.getElementById("username").Focus
.document.getElementById("username").Value = "login"
.document.getElementById("password").Focus
.document.getElementById("password").Value = "password"
.document.All("button1").Click
On Error GoTo 0
While .Busy Or .ReadyState <> 4: DoEvents: Wend
While .Busy Or .ReadyState <> 4: DoEvents: Wend
.document.getElementById("pasta").Focus
.document.getElementById("pasta").Value = NumeroPasta
While .Busy Or .ReadyState <> 4: DoEvents: Wend
While .Busy Or .ReadyState <> 4: DoEvents: Wend
IE.document.parentWindow.execScript "localizar();", "javascript"
While .Busy Or .ReadyState <> 4: DoEvents: Wend
' here is where i suppose to have a code that get the desire value
End With
End Sub
答案 0 :(得分:0)
这个答案需要有关互联网开发技术的基本知识。 我想要理解答案,你应该读一点。我已经包含了链接。
您有两种选择: 1.使用html表单并将值放入输入字段。
<form action="YOUR_HANDLER" method="post">
<table>
<tr class="TRLinha1">
<td class="TDTitulo">Adv. Funcionário</td>
<td class="TDLinha2"><input type="text" id="C2" value="Fulano De tal" /></td>
<td class="TDTitulo">Adv. Credenciado</td>
<td class="TDLinha2"><span id="C3">Escritorio Identidade</span></td>
<td class="TDTitulo" colspan="2">
<img id="imgAdvogadoCredenciado" onclick="fcnShowAdvogadoCredenciado(1)" onmouseover="this.style.cursor='hand'" src="../../../../../../../Portal/Imagens/arquivo.png" alt="Exibir Advogado Credenciado" style="border-width:0px;">
</td>
</tr>
</table>
</form>
&#13;
http://www.w3schools.com/html/html_forms.asp
答案 1 :(得分:0)
您可以尝试在split
上使用document.innerHTML
来获取该字符串,即
Split(Split(.document.innerHTML, "id=""C2"">")(1), " <")(0)