HtmlAgilityPack id 选择

HtmlAgilityPack id selection

我正在构建一个 C# 程序,该程序在网站上运行并采用 span#id。

这是我的代码:

        var web = new HtmlWeb();
        var doc = web.Load(url);
        System.Threading.Thread.Sleep(21000);
        string adress = doc.DocumentNode
              .SelectSingleNode("//td/span#myId")
              .Attributes["value"].Value;

而且我总是收到此错误 "system.Xml.XPath.XpathException" :

谢谢

假设您的 HTML 看起来像这样:

<body>
  <table>
    <tr>
      <td><span id="testedAddress">Some text here</span></td>
    </tr>
  </table>
</body>

那么你想要的XPath就是//td/span[@id='testedAddress']