C# 使用href html agility pack解析表

C# 使用href html agility pack解析表,c#,html-agility-pack,C#,Html Agility Pack,嗨,我想解析表,但我不能完全得到信息 我使用了以下不返回href链接的代码 HtmlNode table = doc.DocumentNode.SelectSingleNode("//table[1]//tbody"); foreach (var cell in table.SelectNodes(".//tr/td")) { string someVariable = cell.InnerText;

嗨,我想解析表,但我不能完全得到信息

我使用了以下不返回href链接的代码

HtmlNode table = doc.DocumentNode.SelectSingleNode("//table[1]//tbody");
            foreach (var cell in table.SelectNodes(".//tr/td"))
            {
                string someVariable = cell.InnerText;
                Debug.WriteLine(someVariable);
       }
我也需要得到href,我该怎么做

<table>
    <tbody>
    <tr>
    <td class="a1">
    <a href="/subtitles/joker-2019/farsi_persian/2110062">
    <span class="l r positive-icon">
    Farsi/Persian
    </span>
    <span>
    Joker.2019.WEBRip.XviD.MP3-SHITBOX
    </span>
    </a>
    </td>
    <td class="a3">
    </td>
    <td class="a40">
    &nbsp;
    </td>
    <td class="a5">
    <a href="/u/695804">
    meisam_t72
    </a>
    </td>
    <td class="a6">
    <div>
    ►► زیرنویس از میثم ططری - ویرایش شده ◄◄ - meisam_t72 کانال تلگرام&nbsp; </div>
    </td>
    </tr>
    </tbody>
    </table>

►► زیرنویس از میثم ططری - ویرایش شده ◄◄ - 我的名字是

在您的
foreach
中,您需要检查单元格内容是否包含
标记。如果它包含属性href,请从此标记获取属性href

类似这样的东西(未经测试)


foreach
中,需要检查单元格内容是否包含
标记。如果它包含属性href,请从此标记获取属性href

类似这样的东西(未经测试)

foreach (var cell in table.SelectNodes(".//tr/td"))
{
    string someVariable = cell.InnerText;
    Debug.WriteLine(someVariable);

    var links = cell.SelectNodes(".//a");
    if (links == null || !links.Any())
    {
        continue;
    }

    foreach (var link in links)
    {
      var href = link.Attributes["href"].Value;
      // do whatever you want with the link.
    }
}