Offline database........?
-
Let's say I have 3 columns: stock symbol, current price, last price. I want to be able to enter the stock symbol and then my app retrieves the current price and last price from, let's say, yahooFinance. In effect I am creating a database by entering ONLY the stock symbol, without access to or connecting with an external database per se (Oracle, SQL, etc). The app populates the remaining fields from the yahooFinance web site and refreshes that information within a predetermined amount of time. I'm brand new to VB so I'd love some guidance with this problem. Also, curious about column sizing. The datagrid properties change each column to the identical size. How can I customize the size of each column seperately? Thanks.
-
Let's say I have 3 columns: stock symbol, current price, last price. I want to be able to enter the stock symbol and then my app retrieves the current price and last price from, let's say, yahooFinance. In effect I am creating a database by entering ONLY the stock symbol, without access to or connecting with an external database per se (Oracle, SQL, etc). The app populates the remaining fields from the yahooFinance web site and refreshes that information within a predetermined amount of time. I'm brand new to VB so I'd love some guidance with this problem. Also, curious about column sizing. The datagrid properties change each column to the identical size. How can I customize the size of each column seperately? Thanks.
It sounds like your going to be scraping a web page for your data. It can be done, but be very careful about how you go about finding the data you want in the page. When, not if, when Yahoo or any other source, changes the page layout, it'll most likely break your app. RageInTheMachine9532
-
It sounds like your going to be scraping a web page for your data. It can be done, but be very careful about how you go about finding the data you want in the page. When, not if, when Yahoo or any other source, changes the page layout, it'll most likely break your app. RageInTheMachine9532
-
Yes, that's it...I want to scrape a web page for my data. Fortunately the site is quite consistent so I do not anticipate having to change my code very often. However, how do I "scrape" a web site? Which method to I employ? What's the best?
"Scrape"ing is grabbing a page and searching through it looking for certain tags or other strings that either delineate the information you want or point to the information you want. In other words, you'll treat the page source (HTML) as a string and search that string for substrings that represents the data you want, or the tags around it. For example:
Last Trade:28.01Trade Time:4:00PM ETChange:
0.29 (1.02%)
This is just a few lines of the 38,000 characters returned by Yahoo Finance to display the data for a quote on Microsoft. There are 3 bits of useful information in this snippet. The "Last Trade", "Trade Time", and "Change". Find them... I'l wait. Now, you can use the strings "Last Trade", "Trade Time", and "Change" to find where the information is, but it doesn't give you the information you want. Once you find the string "Last Trade", you have to skip a bunch of stuff before you can actually get to the data you need, 28.01. The problem is how do you RELIABLY skip to that piece of information? Hint: The web page isn't as stable as it appears! You might want to look at this MSDN article[^] first before deciding whether or not this method is acceptable. RageInTheMachine9532
-
"Scrape"ing is grabbing a page and searching through it looking for certain tags or other strings that either delineate the information you want or point to the information you want. In other words, you'll treat the page source (HTML) as a string and search that string for substrings that represents the data you want, or the tags around it. For example:
Last Trade:28.01Trade Time:4:00PM ETChange:
0.29 (1.02%)
This is just a few lines of the 38,000 characters returned by Yahoo Finance to display the data for a quote on Microsoft. There are 3 bits of useful information in this snippet. The "Last Trade", "Trade Time", and "Change". Find them... I'l wait. Now, you can use the strings "Last Trade", "Trade Time", and "Change" to find where the information is, but it doesn't give you the information you want. Once you find the string "Last Trade", you have to skip a bunch of stuff before you can actually get to the data you need, 28.01. The problem is how do you RELIABLY skip to that piece of information? Hint: The web page isn't as stable as it appears! You might want to look at this MSDN article[^] first before deciding whether or not this method is acceptable. RageInTheMachine9532
Here is something I was playing around with last week. Give it a try. Just pass a list of comma delimited stock quotes to the function. It will return a list of all the quotes with each item having the details of the stock in a comma delimited format: symbol, last trade time, last value, open value, PE, etc... The downside it is not in realtime. Public Function GetQuote(ByVal symbols As String) As StockDetails Dim url As String = "http://quote.yahoo.com/d/quotes.csv?s=" & symbols & "&d=t&f=sl1d1t1c1ohgvj1pp2wern" 'stores url of yahoo quote engine Dim buffer As String Dim webRequest As WebRequest Dim webResponse As WebResponse webRequest = HttpWebRequest.Create(url) webResponse = webRequest.GetResponse() Dim sr As StreamReader = New StreamReader(webResponse.GetResponseStream, System.Text.Encoding.ASCII) buffer = sr.ReadToEnd() sr.Close() Return buffer End Function This should be much easier than obtaining values from an existing web page. Michael