Estimados amigos muy buenos dias, quisiera que por favor me ayuden a que este codigo funcione. Lo que pretendo es extraer datos de esta pagina de la sbs. http://www.sbs.gob.pe/app/spp/Afiliados/afil_detalle.asp?tp=2&tip_doc=00&num_doc=00000000
Código [Seleccionar]
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports HtmlAgilityPack
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Web
Public Class Form2
Sub obtener()
Try
Dim document As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
document.LoadHtml("http://www.sbs.gob.pe/app/spp/Afiliados/afil_detalle.asp?tp=2&tip_doc=00&num_doc=00000000")
Dim NodesTr As HtmlAgilityPack.HtmlNodeCollection = document.DocumentNode.SelectNodes("//table[@id='TblDetalle']//tr")
If NodesTr IsNot Nothing Then
Dim dt As New DataTable()
dt.Columns.Add("DATO1", GetType(String))
dt.Columns.Add("DATO2", GetType(String))
Dim iNumFila As Integer = 0
For Each Node As HtmlNode In NodesTr
If iNumFila > 0 Then
Dim iNumColumna As Integer = 0
Dim dr As DataRow = dt.NewRow()
For Each subNode As HtmlNode In Node.Elements("td")
If (iNumColumna = 0) Then dr = dt.NewRow()
Dim sValue As String = subNode.InnerHtml.ToString().Trim()
sValue = System.Text.RegularExpressions.Regex.Replace(sValue, "<.*?>", " ")
dr(iNumColumna) = sValue
iNumColumna += 1
If iNumColumna = 2 Then '3
dt.Rows.Add(dr)
iNumColumna = 0
End If
Next
End If
iNumFila += 1
Next
dt.AcceptChanges()
Me.dgvHtml.DataSource = dt
Me.dgvHtml.ReadOnly = True
Me.dgvHtml.Columns(0).HeaderText = "DATO1"
Me.dgvHtml.Columns(1).HeaderText = "DATO2"
End If
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class