Getting HTML from a website

Hi guys,
I have a fairly simple question reguarding connecting to the internet in a VB app.

I was just wondering how i might go about getting the HTML from a website using the URL in VB.net.

For instance, in perl you might just say
my @data = get(http://www.google.com/);

How can i do this in VB
Thanks in advance
-Robert



Answer this question

Getting HTML from a website

  • gyurisc

    Imports system.net

    Imports System.IO

    Public Class frmgetHTTP

    Private Function getHTTP(ByVal url As String)

    Dim httpRequest As HttpWebRequest

    Dim httpResponse As HttpWebResponse

    Dim bodytext As String = ""

    Dim responseStream As Stream

    Dim bytes As Int32

    Dim RecvBytes(Byte.MaxValue) As Byte

    httpRequest = CType(WebRequest.Create(url), HttpWebRequest)

    httpResponse = CType(httpRequest.GetResponse, HttpWebResponse)

    responseStream = httpResponse.GetResponseStream()

    Do While (True)

    bytes = responseStream.Read(RecvBytes, 0, RecvBytes.Length)

    If bytes <= 0 Then Exit Do

    bodytext += System.Text.Encoding.UTF8.GetString(RecvBytes, 0, bytes)

    Loop

    Return bodytext

    End Function


  • Roland H

    hi,

    if you want the html as text you can use Webclient

    this is the same question

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=404782&SiteID=1

    hope this helps



  • windyweather

    One way of doing it may be. download the HTML file to a file and then read this file

    My.Computer.Network.DownloadFile(<URL>, <Filename>)
    Dim s as string = My.COmputer.FileSystem.ReadAllText (<Filename>)

    Not the most efficient but it should work.


  • OlyJim

    When I try to do the My.computer it highlites My as an error. Should I be using some specific header file, or why is it not working


  • SP Steve

     

    Another way to do it is like this:

    Protected Friend with events wb as new webBrowser

    Private sub Load_(blah as blah,blah as blah)

    wb.navigate("www.whateverYoururl..com")

    end sub

    Private sub  wb_DocumentComplete (blah as blah,blah as blah) Handles DocumentComplete

    dim text as sting  = wb.document

    end sub

     

     

     



  • Getting HTML from a website