我有像这样的HTML
<li class="in-ttl-b">(a) kanji; a Chinese character [ideograph]
<ul class="list-data-b-in"><li class="text-jejp text-c"><span class="ex">漢字で書く</span></li><li class="text-jeen text-c">write in <i>kanji</i> [<i>Chinese characters</i>]</li></ul>
<ul class="list-data-b-in"><li class="text-jejp text-c"><span class="ex">常用漢字</span></li><li class="text-jeen text-c"><i>Chinese characters</i> for everyday use (in Japan)</li></ul>
</li>
我怎样才能获得kanji; a Chinese character [ideograph]
?
答案 0 :(得分:0)
您可以通过选择第一个文本节点作为外部li
元素的子节点来实现。例如,假设li
class="in-ttl-b"
的{{1}}实例可以有多个:
Dim lis = HTMLDoc.DocumentNode.SelectNodes("//li[@class='in-ttl-b']")
For Each li As HtmlNode in lis
'select the first text node in <li> :
Dim txt = li.SelectSingleNode("text()[1]")
Console.WriteLine(li.InnerText)
Next
<强> dotnetfiddle demo
强>
输出
(a) kanji; a Chinese character [ideograph]