C# 如何将HTML表内容提取到DataTable

C# 如何将HTML表内容提取到DataTable,c#,html,vb.net,parsing,href,C#,Html,Vb.net,Parsing,Href,我有一个html页面,页面中的内容如下所示 我试图将页面中的内容提取到DataTable中,并将其显示到网格中 例如在 <a href='/exodus-5.1/bacon/exodus-5.1-20150612-NIGHTLY-bacon.zip'>exodus-5.1-20150612-NIGHTLY-bacon.zip</a> 尽管不是VB.Net,但使用另一种.Net语言F#和作为Nuget可用部分的实现这是一项非常简单的任务 HTML类型提供程序为您提供对V

我有一个html页面,页面中的内容如下所示

我试图将页面中的内容提取到DataTable中,并将其显示到网格中

例如在

<a href='/exodus-5.1/bacon/exodus-5.1-20150612-NIGHTLY-bacon.zip'>exodus-5.1-20150612-NIGHTLY-bacon.zip</a>

尽管不是VB.Net,但使用另一种.Net语言F#和作为Nuget可用部分的实现这是一项非常简单的任务

HTML类型提供程序为您提供对VisualStudio内HTML文档的类型化访问,即

// Reference the FSharp.Data Nuget package
#r @".\packages\FSharp.Data.2.2.3\lib\net40\FSharp.Data.dll"
// Type provider over your HTML document specified in yourUrl
type html = FSharp.Data.HtmlProvider<yourUrl>
// Get the rows from the HTML table in the page
let allRows = html.GetSample().Tables.Table1.Rows |> Seq.skip 1
// Skip empty rows
let validRows = allRows |> Seq.where (fun row -> row.Name <> "")
最后在表单上显示DataTable:

// Reference the Windows.Forms assembly
#r "System.Windows.Forms.dll"
open System.Windows.Forms
// Create a form
let form = new Form(Width=480,Height=320)
// Initialise a grid
let grid = new DataGridView(Dock=DockStyle.Fill)
form.Controls.Add(grid)
// Set the grid data source with the table
form.Load.Add(fun _ -> grid.DataSource <- table)
form.Show()
//引用Windows.Forms程序集
#r“System.Windows.Forms.dll”
打开System.Windows.Forms
//创建表单
让形状=新形状(宽度=480,高度=320)
//初始化网格
让grid=newdatagridview(Dock=DockStyle.Fill)
form.Controls.Add(网格)
//使用表格设置网格数据源

form.Load.Add(fun->grid.DataSource现在你已经有了页面的内容,你需要这样做。在你抓取了所需的信息之后,你就可以了。
// Reference the System.Data assembly
#r "System.Data.dll"
// Create a DataTable
let table = new System.Data.DataTable()
// Add column names to the table
for name in ["Parent";"Name";"Last modified";"Size"] do table.Columns.Add(name) |> ignore
// Add row values to the table
for row in validRows do
  table.Rows.Add(row.Column1, row.Name, row.``Last modified``, row.Size) |> ignore
// Reference the Windows.Forms assembly
#r "System.Windows.Forms.dll"
open System.Windows.Forms
// Create a form
let form = new Form(Width=480,Height=320)
// Initialise a grid
let grid = new DataGridView(Dock=DockStyle.Fill)
form.Controls.Add(grid)
// Set the grid data source with the table
form.Load.Add(fun _ -> grid.DataSource <- table)
form.Show()