Estrarre dati web VISUAL BASIC 2010

sabato 31 dicembre 2011 - 12.44
Tag Elenco Tags  VB.NET  |  .NET 4.0  |  Windows 7  |  Visual Studio 2010  |  SQL Server 2008 R2  |  Office 2010  |  Internet explorer 8.0  |  Chrome  |  Firefox  |  VBScript  |  HTML 5  |  Crystal Reports 8.5

valebes Profilo | Newbie

Scusate se faccio qualche errore ma sono nuovo in questo forum
Iosto facendo un programma in VB 2010 che serve ad estrarre i dati (Nome società,Indirizzo,telefono,cellulare) da una pagina html.
Per fare un esempio il mio programma deve estrarre i dati da http://aziende.iopubblicita.it/search/?cosa=Ristoranti&dove=SICILIA&indirizzo=.

Mi scarica il codice html ma anche se ho provato di tutto non riesco ad eliminare quello che non mi serve,mi potete aiutare???Ah Se potete mi potete dare un codice per salvare i dati ricavati in un foglio excel.

Caratteristiche Form:
2 Textbox
1 Button

Il codice Form 1:
Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.ObjectModel
Imports System.Drawing.Drawing2D


Public Class Form1
Public Function EstraiTestoDaHTML(ByVal HTML As String) As String

Return System.Text.RegularExpressions.Regex.Replace( _
HTML, "<[^>]*>", "")
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = Image.FromFile("logopc009.gif")
My.Computer.Audio.Play("Default_Title.wav", AudioPlayMode.WaitToComplete)
PictureBox2.Image = Image.FromFile("browser.gif")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

My.Computer.Audio.Play("Ok.wav", AudioPlayMode.WaitToComplete)
Dim URL As String

URL = TextBox2.Text

Dim objScaricaURL As New ScaricaURL

objScaricaURL.SetURL(URL)


Me.TextBox1.Text = _
System.Text.RegularExpressions.Regex.Replace( _
objScaricaURL.Scarica, "<[^>]*>", "")







My.Computer.Audio.Play("Yes.wav", AudioPlayMode.WaitToComplete)


End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Computer.Audio.Play("dfdd.wav", AudioPlayMode.WaitToComplete)
End Sub


CODICE CLASS 1:

Imports System.Text

Imports System.IO

Imports System.Net

Public Class ScaricaURL

Private m_strURL As String

Public Sub SetURL(ByVal strURL As String)

m_strURL = strURL

End Sub

Public Function Scarica() As String

Dim wreq As WebRequest = WebRequest.Create(m_strURL)

Dim wres As WebResponse = wreq.GetResponse()

Dim iBuffer As Integer = 0

Dim buffer(128) As [Byte]

Dim stream As Stream = wres.GetResponseStream()

iBuffer = stream.Read(buffer, 0, 128)

Dim strRes As New StringBuilder("")

While iBuffer <> 0

strRes.Append(Encoding.ASCII.GetString(buffer, 0, iBuffer))

iBuffer = stream.Read(buffer, 0, 128)

End While

Return strRes.ToString()

End Function

End Class

Jeremy Profilo | Guru

Ciao Valerio.
Devi lavorare tanto di Regular Expression ..... fortunamente chi ha costruito il sito, ha assegnato ad ogni componente dell'indirizzo una classe CSS
Facci sapere....
Ciao.

valebes Profilo | Newbie

Grazie mille ci sono riuscito
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5