tambien tengo este codigo quizas es a lo que te refieres
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
Dim doc2 As New HtmlAgilityPack.HtmlDocument()
Dim wc As New WebClient
Dim regexTrim As New Regex("\s\s", RegexOptions.Compiled)
Private bConsultado As Boolean = False
Private bResultado As Boolean = False
Private sHtml As String = ""
Private periodo As String = ""
Public Function Consultar(ByVal dni As String) As resultados
Dim elemento As HtmlNode
Dim tablaStr As String
x:
Dim bytes As Byte()
bytes = wc.DownloadData("http://www.sbs.gob.pe/app/spp/Afiliados/afil_detalle.asp?tp=2&tip_doc=00&num_doc=" & dni)
Using sr As New StreamReader(New MemoryStream(bytes))
doc2.LoadHtml(HttpUtility.HtmlDecode(sr.ReadToEnd()))
End Using
elemento = doc2.DocumentNode.SelectSingleNode("//html")
If elemento Is Nothing Then
GoTo x
End If
' posible bucle infinito
tablaStr = elemento.InnerHtml
MsgBox(tablaStr)
' posible bucle infinito (poco probable)
Dim result As New resultados()
If tablaStr.Contains("Documento de Identidad no registrado en el SPP.") Then
result.Estado = resultados.RucState.NoExiste
Return result
End If
' nombre comercial
result.EstadoContribuyente = ObtenerContenido(elemento, "Apellido Paterno")
' estado del contribuyente
result.CondiciónContribuyente = ObtenerContenido(elemento, "Primer Nombre")
' condición del contribuyente
result.Dirección = ObtenerContenido(elemento, " Fecha Nacimiento")
' dirección
Return result
End Function
Private Function ObtenerContenido(tabla As HtmlNode, index As String) As String
Dim elemento As HtmlNode = Nothing
For Each e As HtmlNode In tabla.ChildNodes
If Not String.IsNullOrEmpty(e.InnerText) AndAlso e.InnerText.Contains(index) Then
elemento = e
Exit For
End If
Next
If elemento Is Nothing OrElse elemento.ChildNodes.Count = 0 Then
Return String.Empty
End If
Return TrimAll(elemento.ChildNodes(3).InnerText)
End Function
Private Function TrimAll(str As String) As String
While regexTrim.IsMatch(str)
str = regexTrim.Replace(str, " ")
End While
Return str.Trim()
End Function
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim result As resultados = Consultar("06454380")
Select Case result.Estado
Case resultados.RucState.NoExiste
MessageBox.Show("El RUC no existe.")
Case resultados.RucState.Normal
TextBox1.Text = "Número de RUC: " & result.RUC & vbNewLine &
"Tipo Contribuyente: " & result.TipoContribuyente & vbNewLine &
"Tipo de Documento: " & result.TipoDocumento
End Select
End Sub
End Class
Public Class resultados
Public Estado As RucState
Public RUC As String
Public TipoContribuyente As String
Public TipoDocumento As String
Public NombreComercial As String
Public EstadoContribuyente As String
Public CondiciónContribuyente As String
Public Dirección As String
Public Enum RucState
Normal
NoExiste
End Enum
End Class