?
Solved

Pull HTML Code for a Website Using VB.net

Posted on 2004-04-23
2
Medium Priority
?
602 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 1400 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

771 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