2012-05-04 58 views
0

我有div元素文本中嵌套的div的div htmlagilitypack

<div title="View this search: Actives"> 
<div style="float:right;"> 
<span class="count" title="some title" id="search_201204"> 
34 New or Changed 
</span> 
<span id="trash_2012">&nbsp;&nbsp;X</span> 
</div> 
The value i need 
<div style="padding-left:20px;color:#888"></div> 
</div> 

我需要得到與標題外div的的innerText包含some title

我有這樣的代碼

divs = docNode.SelectNodes("//div[contains(@title, 'View this search:')]") 
If divs Is Nothing Then Continue For 
For Each div In divs 
    If div Is Nothing Then Continue For 
    If ListSearch.Contains(div.InnerText) = False Then 
     ListSearch.Add(div.InnerText) 
    End If 
Next 

這給了我

34新增功能或變更    XThe值,我需要

,而不是

我需要的價值

這是外部div的文本。

請提供您擁有的任何解決方案。

感謝

回答

1

嘗試使用以下XPath:

//div[contains(@title, 'View this search:')]/child::text()/following-sibling::text() 
+0

非常感謝。你是否在構建這個聲明時使用了任何工具,或者你是如何弄清楚的? – Smith

+0

沒有工具,只是xpath文檔)) – Mike

+0

請你能給我這個文檔?再次感謝 – Smith