locked
Web Query RRS feed

  • Question

  • User-933610287 posted

    I'm looking for some guidance and hoping this forum can point me to the right direction.

    I'm not sure if this can be done using vb.net, but is it possible to download a web query into a database (preferably Access), then display the results in a gridview? I'm not even sure if "web query" is the correct terminology, but ms excel has this feature where you can import data into a spreadsheet.  I was interested in doing something similar - pull data off a website (e.g. stock prices) at a set interval, like every 30min - then display the data in an asp.net page.

    Thanks.


    Thursday, March 11, 2010 9:33 AM

Answers

  • User197322208 posted

    HtmlAgility Pack with a XML notion is the best approach

    http://blogs.msdn.com/smourier/archive/2003/06/04/8265.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 11:14 AM

All replies

  • User197322208 posted

    HtmlAgility Pack with a XML notion is the best approach

    http://blogs.msdn.com/smourier/archive/2003/06/04/8265.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 11:14 AM
  • User-933610287 posted

    great!  thanks for the quick response.  i'll check out the link and start doing research on this topic.

    Thursday, March 11, 2010 11:34 AM
  • User-933610287 posted

    I found a good article on screen scraping but i'm having trouble getting the code to run.

    http://www.dotnetjohn.com/articles.aspx?articleid=93

    i'm getting an error at line 11, "strHTML = streamReader.ReadToEnd", saying "Variable 'streamReader' is used before it has been assigned a value..."

    here is the code behind.  any help is appreciated...

    Partial Class _Default
        Inherits System.Web.UI.Page
    
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim strURL As String = "http://finance.yahoo.com/q?s=msft"
            Dim objWebRequest As System.Net.HttpWebRequest
            Dim objWebResponse As System.Net.HttpWebResponse
            Dim streamReader As System.IO.StreamReader
            Dim strHTML As String
            strHTML = streamReader.ReadToEnd
    
            objWebRequest = CType(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest)
            objWebRequest.Method = "GET"
            objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)
    
            streamReader = New System.IO.StreamReader(objWebResponse.GetResponseStream)
            strHTML = streamReader.ReadToEnd
    
            Dim intPos1, intPos2, intPos3 As Integer
    
            intPos1 = strHTML.IndexOf("Last Trade:", 0)
            intPos2 = strHTML.IndexOf("<b>", intPos1)
            intPos3 = strHTML.IndexOf("</b>", intPos2)
            lblPrice.Text = strHTML.Substring(intPos2 + 3, intPos3 - intPos2 + 3)
    
            streamReader.Close()
            objWebResponse.Close()
            objWebRequest.Abort()
        End Sub
    
    
    End Class


    Thursday, March 11, 2010 1:25 PM