</div>
<p id="content-profile-view">
<h3 class="content-profile-title" id="content-profile-title-profile">
Member Profile </h3>
<div class="content-profile-display" id="content-profile-display-profile">
<fieldset class="fieldgroup group-membership"><legend>Membership</legend><div class="field field-type-text field-field-membertype">
<div class="field-items">
<div class="field-item odd">
<div class="field-label-inline-first">
Member Type: </div>
Fellow </div>
</div>
</div>
在上面的html中,我想返回Memeber Type:Fellow。我的下面的代码会给我会员类型:但是我似乎无法获得会员资格。请参阅下面的代码vba。
Dim collection As MSHTML.IHTMLElementCollection
Dim element As MSHTML.HTMLInputElement, subElement As MSHTML.HTMLInputElement
Dim a As String
Dim b As String
Set collection = Doc.getElementsByTagName("div")
For Each element In collection
If element.className = "field-label-inline-first" Then
a = element.innerText
Debug.Print a
End If
Next element
答案 0 :(得分:1)
要获取第二个数据,你需要查找带有'field-item'类的div,因为者包含在整个div中,而不是field-label-inline-first div
我已经重新格式化了以下内容,以便更明显地发生了什么。
<div class="field-item odd">
<div class="field-label-inline-first">Member Type: </div>
Fellow
</div>