Retrive html content using System.Net.HttpWebRequest Romania
  • 13 years ago


    I want to retrive some html content from a given website. For that I use the System.Net.HttpWebRequest:

    Dim connectionString As String = "some url here"

    Dim myRequest As
    System.Net.HttpWebRequest = WebRequest.Create(connectionString)
                myRequest.Credentials = CredentialCache.DefaultCredentials

    '// Get the response

       Dim webResponse As WebResponse = myRequest.GetResponse
       Dim respStream As Stream = webResponse.GetResponseStream


       Dim ioStream As StreamReader = New StreamReader(respStream)
       Dim pageContent As String = ioStream.ReadToEnd


    '// Close streams

    Catch ex As Exception
            Me.Label1.Text = ex.Message

    End Try


    The above code works, but the problem is that it retrieves all the html content...and I don't nee it all.

    All I need is all the content between <head> and </head>


    [ originally posted on ]

  • 13 years ago

    Just parse the html and take what's between the head tags.

    The nature of the request is that you can't specify that you want just the head tags, because the server always sends the full data when it gets a request.

  • 13 years ago

    Hi pcmattman, and thank you for the reply!

    I thought about what you've said myself, but there is a problem...I don't know how to do it Sad [:(]...

    I've searched the net and I couldn't find an example on how to do it...They were only showing the way of retrieving all the content and not parts of it.

    I'm a seo consultant and a web designer. I always liked VB but my knowledge is limited though...
    (I use programming only when I have to)

    Maybe you can help me providing a sample code, please?


    [ I should start learn more...]

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan