好的,我需要查询实时网站以从表中获取数据,将此HTML表放入DataTable然后使用此数据.到目前为止,我已经设法使用Html Agility Pack和XPath来获取我需要的表中的每一行,但我知道必须有一种方法可以将其解析为DataTable.(C#)我目前使用的代码是:
string htmlCode = "";
using (WebClient client = new WebClient())
{
htmlCode = client.DownloadString("http://www.website.com");
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlCode);
//My attempt at LINQ to solve the issue (not sure where to go from here)
var myTable = doc.DocumentNode
.Descendants("table")
.Where(t =>t.Attributes["summary"].Value == "Table One")
.FirstOrDefault();
//Finds all the odd rows (which are the ones I actually need but would prefer a
//DataTable containing all the rows!
foreach (HtmlNode cell in doc.DocumentNode.SelectNodes("//tr[@class='odd']/td"))
{
string test = …Run Code Online (Sandbox Code Playgroud)