HTMLAgilityPack获取<;P>;及<;STRONG>;文本

HTMLAgilityPack获取<;P>;及<;STRONG>;文本,html,vb.net,html-parsing,html-agility-pack,Html,Vb.net,Html Parsing,Html Agility Pack,嘿,我正在寻找一种方法来获取此HTML代码: 2WGNAMER 使用HtmlAgilityPack 我一直在尝试: For Each channel In doc.DocumentNode.SelectNodes(".//div[@class='channel_row']") Dim info = New Dictionary(Of String, Object)() With channel info!Logo = .SelectSingleNode(".//i

嘿,我正在寻找一种方法来获取此HTML代码:


2
WGNAMER

使用HtmlAgilityPack

我一直在尝试:

For Each channel In doc.DocumentNode.SelectNodes(".//div[@class='channel_row']")
   Dim info = New Dictionary(Of String, Object)()

   With channel
      info!Logo = .SelectSingleNode(".//img").Attributes("src").Value
      info!Channel = .SelectSingleNode(".//span[@class='channel']").ChildNodes(1).ChildNodes(0).InnerText
      info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(1).ChildNodes(2).InnerText
   End With
.......
我可以得到这个标志,但它为频道和电台提供了一个空白字符串

索引超出范围。必须为非负数且小于 收藏

我尝试了所有类型的组合:

info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(1).ChildNodes(1).InnerText
info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(1).ChildNodes(3).InnerText
info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(0).ChildNodes(1).InnerText
info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(0).ChildNodes(2).InnerText
info!Station = .SelectSingleNode(".//span[@class='channel']").ChildNodes(0).ChildNodes(3).InnerText
要更正此问题,我需要做什么


如果空格实际存在,则它将被视为子节点。因此:

Dim channelSpan = .SelectSingleNode(".//span[@class='channel']")

info!Channel = channelSpan.ChildNodes(3).ChildNodes(0).InnerText
info!Station = channelSpan.ChildNodes(3).ChildNodes(2).InnerText
Dim channelSpan=.SelectSingleNode(“.//span[@class='channel']”)
信息!Channel=channelSpan.ChildNodes(3).ChildNodes(0).InnerText

信息!Station=channelSpan.ChildNodes(3).ChildNodes(2).当我这样做时,InnerText索引现在超出了频道的范围。@StealthRT:channelSpan.ChildNodes.Count的
?再次检查OP。@StealthRT:展开
ChildNodes
并查找
Count
属性。其中有4个。。。更新OP