vba在div中检索href

问题描述 投票:0回答:2

我想在网页中检索电子邮件地址,其中包含以下HTML:

`<div id="responseDiv" style="background-color:#EBECED;width: 450px;">
<font style="letter-spacing: 0pt" size="3" face="Arial" 
color="#336699">
&nbsp;&nbsp;&nbsp;  
<a href="mailto:[email protected]?subject=Resposta Anuncio Net-                                   Empregos: TI SQL e VB.net" target="_blank">**[email protected]**
<div></div>
<div></div>
</a>
</font></div>

`

到目前为止,我已经尝试了以下内容,除了我想要的电子邮件地址之外,还会填充该页面中的所有内容:

Dim dataEle As Object, vElemento As String, tit as string
Set dataEle =Doc.getElementsByTagName("p") ' also tryed with element "a"

For Each element In dataEle
  tit = element.getAttribute("href") 
  MsgBox (tit)
Next

可能是,因为元素“a”是Div的一部分吗? (responseDiv)谢谢

access-vba
2个回答
0
投票

我确实测试了与您的html div字符串相关联的代码,其中包含许多电子邮件,如附图所示,以确保您。

只要记住,如果该html div字符串是常量字符串,这个解决方案将按你想要的方式工作:

Private Sub CmdRetrieveHrefInsideDiv_Click()
Dim test As String
Dim frstWrd As String
test = Text1.Value
frstWrd = Split(test, ":")(4)
Dim X As Integer
X = InStr(frstWrd, "?")
Dim MyEmail As String
MyEmail = Split(frstWrd, "?")(0)
MsgBox MyEmail
End Sub

我希望这可以帮到你^ _ ^

enter image description here

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