Solved

Pull HTML Code for a Website Using VB.net

Posted on 2004-04-23
2
596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 350 total points
ID: 10906415
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
ID: 10918134
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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