从c#中的网页刮取表

Mic*_*ael 2 html c# datatable scrape

构建函数以将网页上的html表刮入变量的最佳方法是什么?

我希望能够传递一些唯一的标识符(如表ID或其他东西),它会将所有数据返回到像DataTable这样的东西.

Bro*_*ass 5

您可以使用HtmlAgilityPack来解析HTML并提取表数据.

随着HAP现在支持Linq你可以从这样的事情开始:

HtmlDocument doc = ...
var myTable = doc.DocumentNode
                 .Descendants("table")
                 .Where(t =>t.Attributes["id"].Value == someTableId)
                 .FirstOrDefault();

if(myTable != null)
{
    ///further parsing here
}
Run Code Online (Sandbox Code Playgroud)