Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Guys & Gals

 

I have a new project and I'm not really sure how to start at all. Basically I will be iterating through a set of web pages and performing actions depending on the page's source. So my first task is to find how to get a copy of the HTML behind a page on the net.

 

The only thought I have had is to use the Web Browser control, but even then I have no idea if it has the methods I require to obtain the source code of a page.

 

Thoughts?

 

JWA

  • Administrators
Posted

Easiest option is probably the System.Net.WebClient class as it provides a simple DownloadData method that will return a URL as a byte array, this can easily be turned into a string via a StreamReader object or one of the classes under System.Text

 

       Dim x As New System.Net.WebClient()

       Dim b() As Byte = x.DownloadData("http://www.microsoft.com")

       Dim ms As New System.IO.MemoryStream(b)
       Dim sr As New IO.StreamReader(ms)

       Dim s As String = sr.ReadToEnd

       MessageBox.Show(s)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Brilliant this does the trick.... to an extent. On some sites I get 502 errors returned from the web server!

 

Any ideas?

 

JWA

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...