Solved

Pull HTML Code for a Website Using VB.net

Posted on 2004-04-23
2
559 Views
Last Modified: 2007-12-19
I have some experience using VB 6.0, but would like to learn VB.net.  A project I would like to begin with is this:

I would like to create code that would go to a particular website, say something like www.yahoo.com.  I then want to save the HTML code for that site to a text file on my PC.  Is this possible?  If so, how would I begin?

Thanks!
0
Comment
Question by:hteel
2 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 350 total points
Comment Utility
Imports System.IO
Imports System.Net

Dim url As String = "http://www.yahoo.com"
Dim ws As WebClient = New WebClient
Dim htmlCode As String = System.Text.Encoding.ASCII.GetString(ws.DownloadData(url))
htmlCode = htmlCode.Replace(Chr(10), vbCrLf)
Dim sw As StreamWriter = New StreamWriter("c:\webpage.txt")
sw.Write(htmlCode)
sw.Close()

This block of code will retrieve the HTML code from Yahoo! and save it to c:\webpage.txt. In your real program you'll probably want to change this around a bit, but this should get you going.
0
 
LVL 27

Expert Comment

by:planocz
Comment Utility
Hi  hteel,

Here is some code that I use...
Add Reference........ AxInetCtlsObjects.dll

Private sWebCode as string
   
 Private Sub LoadData()
        Dim sFile As String

        Try
            'This will display the final screen of data from USAPUB
            sFile = "http://MyWebsiteSearch"      '<---- Replace with your url, Copy source code from web site
            sWebCode = AxInet.OpenURL(sFile)
            WriteCodeTo(sWebCode)               '<---make a procedure to write string to a text file (a streamWriter).
        Catch exp As NullReferenceException
        Catch exp As Runtime.InteropServices.COMException
        Catch exp As Exception
            MsgBox(exp.Message, MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now