CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2002
    Posts
    305

    Downloading a table from a web page

    I would like to download a table on a web page to a .csv or text file using VB.Net (not ASP.Net). Any ideas?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Downloading a table from a web page

    Where is this web page, on the internet, or is it just a web page on your system ¿

    If you want to download code from a webpage on the internet, this will give you a good start :
    Code:
    Imports System.Net 'web request, web response
    Imports System.IO 'streamreader
    Imports System.Text 'encoding
    
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Friend Function GetHtmlCode(ByVal URL As String) As String
            Dim WebRq As HttpWebRequest
            WebRq = System.Net.HttpWebRequest.Create(URL)
            Dim WebRsp As HttpWebResponse
            WebRsp = WebRq.GetResponse()
            Dim strmR As StreamReader = New StreamReader(WebRsp.GetResponseStream(), Encoding.ASCII)
            Dim sLine As String = strmR.ReadToEnd
            strmR.Close()
            Return sLine
        End Function
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim str As String
            str = GetHtmlCode("http://www.codeguru.com/forum/showthread.php?t=409011")
            TextBox1.Text = TextBox1.Text & str
        End Sub
    This will read the entire contents of the file into a textbox

  3. #3
    Join Date
    Dec 2002
    Posts
    305

    Re: Downloading a table from a web page

    HannestheGreat:

    Thanks for your quick reply. Yes, the table is from Internet. However, I don't want to get the result in html format; I have been able to do that and parse data to get what I want. But it is too cumbersome.

    I am looking for a .csv format. For example, I would like to get the call and put options listed in the table at http://finance.yahoo.com/q/op?s=AAPL in.csv format so that retrieval of individual values from the table becomes a cinch.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured