Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page
Extract HTML from a redirected page Extract HTML from a redirected page
Extract HTML from a redirected page
Go Back  Xtreme Visual Basic Talk > > > Extract HTML from a redirected page


Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2011, 10:36 PM
HD666 HD666 is offline
Newcomer
 
Join Date: Nov 2011
Posts: 1
Default Extract HTML from a redirected page


Hello,

I am using visual basic 2005. I found on the web the following function that extracts HTML from webpages. It is very useful but unfortunately it does not work with redirected pages. That is, when I put in it a URL of a redirect page it gives me nothing or error. I added to it ".AllowAutoRedirect = True" but still it did not work. I wonder how to make it work for redirected pages.

I appreciate the help.

Code:
Public Function GetPageHTML(ByVal URL As String, _
      Optional ByVal TimeoutSeconds As Integer = 10) _
     As String
        ' Retrieves the HTML from the specified URL,
        ' using a default timeout of 10 seconds
        Dim objRequest As Net.HttpWebRequest
        Dim objResponse As Net.HttpWebResponse
        Dim objStreamReceive As System.IO.Stream
        Dim objEncoding As System.Text.Encoding
        Dim objStreamRead As System.IO.StreamReader

        Try
            ' Setup our Web request
            objRequest = Net.WebRequest.Create(URL)
            objRequest.Method = "GET"
            objRequest.KeepAlive = True
            objRequest.AllowAutoRedirect = True
            objRequest.Timeout = TimeoutSeconds * 1000
            ' Retrieve data from request
            objResponse = objRequest.GetResponse()
            objStreamReceive = objResponse.GetResponseStream
            objEncoding = System.Text.Encoding.GetEncoding( _
                "utf-8")
            objStreamRead = New System.IO.StreamReader( _
                objStreamReceive, objEncoding)
            ' Set function return value
            GetPageHTML = objStreamRead.ReadToEnd()
            ' Check if available, then close response
            If Not objResponse Is Nothing Then
                objResponse.Close()
            End If
        Catch
           Return "error"
        End Try
    End Function
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page Extract HTML from a redirected page
Extract HTML from a redirected page
Extract HTML from a redirected page
 
Extract HTML from a redirected page
Extract HTML from a redirected page
 
-->