我试图从远程页面抓取html表格,并在我的网站上的htmltable中显示此表格的内容。我正在使用htmlagility包。到目前为止,这里是我的代码:从html中提取表格转换为html.net中的htmltable vb(htmlagilitypack)
Imports HtmlAgilityPack
Partial Class ContentGrabExperiment
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'fetch the remote html page
Dim web As New HtmlWeb()
Dim html As HtmlAgilityPack.HtmlDocument = web.Load("http://www.thesite.com/page.html")
'Create table
Dim outputTable As New HtmlTable
Dim tableRow As New HtmlTableRow
Dim tableCell As New HtmlTableCell
'Target the
For Each table As HtmlNode In html.DocumentNode.SelectNodes("//table")
'Target the
tags within the tableFor Each row As HtmlNode In table.SelectNodes("//tr")
'Target the
tags within the tagsFor Each cell As HtmlNode In row.SelectNodes("//td")
'Set the value to that of the
tableCell.InnerText = cell.InnerHtml
'Add the cell to the row
tableRow.Cells.Add(tableCell)
Next
'Add row to the outputTable
outputTable.Rows.Add(tableRow)
Next
Next
'Add the table to the page
PlaceHolderTable.Controls.Add(outputTable)
End Sub
End Class
从此我期待得到充分的表从页面的innerText,作为HTMLTABLE,我可以再操作。我得到这个代码是:
|
请有人指出我的错误与我的语法。任何帮助非常感谢!
2011-09-22
Phil