Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用HtmlAlityPack解析HTML中的数据_C#_Html_Parsing_Html Agility Pack - Fatal编程技术网

C# 使用HtmlAlityPack解析HTML中的数据

C# 使用HtmlAlityPack解析HTML中的数据,c#,html,parsing,html-agility-pack,C#,Html,Parsing,Html Agility Pack,从下面的源代码中,我想提取内部文本“我的名字”,但我可以挑出1个href节点,取而代之的是整个href列表: <tr class="index"> <td class="number">1.</td> <td class="image"> <a href="/image/520211/" title="My index"> <img src=" /images/M/MV5MDE.jpg" height="7

从下面的源代码中,我想提取内部文本“我的名字”,但我可以挑出1个href节点,取而代之的是整个href列表:

<tr class="index">
  <td class="number">1.</td>
  <td class="image">
    <a href="/image/520211/" title="My index">
    <img src=" /images/M/MV5MDE.jpg" height="74" width="54" alt="My Alt" title="My Title">
    </a>
  </td>
  <td class="name">
    <span class="name_wrapper" data-size="small" data-caller-name="search">
    </span>
    <a href="/data/520211/">My Name</a>
    <span class="year">1974</span>
  </td>
</tr>

1.
1974
到目前为止,我的代码是:

for (var index = 0; index < htmlDocument.DocumentNode.SelectNodes("//tr[@class=index']//a[@href]").Count; index++)
{
    var item = htmlDocument.DocumentNode.SelectNodes("//tr[@class=index']//a[@href]")[index];
    MessageBox.Show(item.InnerText);
}
for(var index=0;index
试试这个:

string name = "";
var node = htmlDocument.DocumentNode
    .SelectSingleNode("//tr[@class='index']//td[@class='name']//a[@href]");
if (node != null)
    name = node.InnerText;