VBA – 通过标签属性提取值
我一直在使用下面的代码来从网页中提取值。
Private Sub Update() Dim IE As New InternetExplorer IE.Visible = False IE.navigate "cisco.com/" & Range("srNum").Value Do DoEvents Loop Until IE.readyState = READYSTATE_COMPLETE Dim Doc As HTMLDocument Set Doc = IE.document Dim sTag As String sTag = Doc.getElementById("caseheader").innerText Sheets.Add ActiveCell.Value = sTag End Sub
我现在正在一个新的页面,我需要通过属性“标题”拉值。 在下面的例子中,我需要find属性“标题”的值“优先”,然后返回“P3”的值。
<div class="con-LFloat con-RAlign con-Priority Width25"> <span class="con-text-bold Width20 con-RAlign">Priority :</span> <span class="con-text-bold con-LMargin5" title="Priority">P3</span> </div>
我曾尝试使用.item(0)或.Children(0)没有运气,我还没有find任何文件来通过它。
我需要一些帮助,或者可以帮助我设置的网站。
-谢谢
尝试添加这样的东西:
Dim htmlEle1 as IHTMLElement On Error Resume Next For Each htmlEle1 in Doc.All If htmlEle1.getAttribute("title") = "Priority" then Debug.Print htmlEle1.innertext Next htmlEle1 On Error GoTo 0
还要将IE.readyState = READYSTATE_COMPLETE
改为IE.readyState = READYSTATE_COMPLETE And IE.Busy = False