Shop OBEX P1 Docs P2 Docs Learn Events
Downloading a web page in Visual Basic 2008 — Parallax Forums

Downloading a web page in Visual Basic 2008

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2010-04-25 00:35 in General Discussion
I am wondering how I should download a webpage in VB 2008 given the URL in·a string format and outputing the downloaded webpage (html & other script) in a string format as well. Can someone tell me how this should be done?

Thanks,
Micro

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!!

Use the Propeller icon!! Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-04-24 20:54
    Hi Microcontrolled , I am assuming you want to view the web page plus view the source . Create a new VB application and from the toolbox drag over 1 button , 1 textbox , 1 webrowser and 1 richtextbox and arrange them how you would like.
    The following is all the code needed for a simple example
    [color=#0000ff][color=#0000ff]Private[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color] Button1_Click([color=#0000ff][color=#0000ff]ByVal[/color][/color] sender [color=#0000ff][color=#0000ff]As[/color][/color] System.Object, [color=#0000ff][color=#0000ff]ByVal[/color][/color] e [color=#0000ff][color=#0000ff]As[/color][/color] System.EventArgs) [color=#0000ff][color=#0000ff]Handles[/color][/color] Button1.Click
    [color=#0000ff][color=#0000ff]Dim[/color][/color] page_url [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color] = TextBox1.Text
    WebBrowser1.Navigate(page_url)
    [color=#0000ff][color=#0000ff]End[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color]
     
    [color=#0000ff][color=#0000ff]Private[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color] WebBrowser1_DocumentCompleted([color=#0000ff][color=#0000ff]ByVal[/color][/color] sender [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]Object[/color][/color], [color=#0000ff][color=#0000ff]ByVal[/color][/color] e [color=#0000ff][color=#0000ff]As[/color][/color] System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) [color=#0000ff][color=#0000ff]Handles[/color][/color] WebBrowser1.DocumentCompleted
    [color=#0000ff][color=#0000ff]Dim[/color][/color] pagesource [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color] = WebBrowser1.DocumentText
    RichTextBox1.Text = pagesource
    [color=#0000ff][color=#0000ff]End[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color]
    
    

    type the url in textbox1 and click button1

    Jeff T.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-04-24 23:22
    Wow, thanks!! I'll try that out!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"

    Post Edited (Microcontrolled) : 4/24/2010 11:30:17 PM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-04-24 23:40
    As a side note , if the WebBrowser is not already in your VB toolbox here is what you should do.

    Right click on the toolbox area

    Select "Choose Items..."

    Under the ".NET Framwork Components" tab scroll down to WebBrowser

    Place a check in the checkbox and click OK

    Jeff T.
  • localrogerlocalroger Posts: 3,452
    edited 2010-04-25 00:35
    uC'ed, I use a standard command prompt application called "httpget." There are several implementations free for downloading, easily found via the mighty GOOG. I shell to it with a command line specifying the URL and file I want. This has the advantage of not tying up the application thread if there is a delay in the networking.
Sign In or Register to comment.