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
Solved

Pull HTML Code for a Website Using VB.net

Posted on 2004-04-23
2
587 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
write xml in vb.net 2 33
Database Connections Not being returned to Connection Pool 7 34
VB.net Progress Bar - Maximum Value too large 2 15
Passing data between Forms 3 20
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

837 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