Parsing HTML page with HtmlAgilityPack

后端 未结 2 1056
故里飘歌
故里飘歌 2020-11-27 14:57

Using C# I would like to know how to get the Textbox value (i.e: john) from this sample html script :


2条回答
  •  伪装坚强ぢ
    2020-11-27 15:27

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(html);
    XPathNavigator docNav = doc.CreateNavigator();
    
    XPathNavigator node = docNav.SelectSingleNode("//td/input/@value");
    
    if (node != null)
    {
        Console.WriteLine("result: " + node.Value);
    }
    

    I wrote this pretty quickly, so you'll want to do some testing with more data.

    NOTE: The XPath strings apparently have to be in lower-case.

    EDIT: Apparently the beta now supports Linq to Objects directly, so there's probably no need for the converter.

提交回复
热议问题