I want to make a program that will find strings of text in a websites source and then display em' in a listbox. Does anybody know of an example or maybe some code that i could learn from??
Printable View
I want to make a program that will find strings of text in a websites source and then display em' in a listbox. Does anybody know of an example or maybe some code that i could learn from??
Anything??
perhaps if we had a better idea of what is is you're trying to do.
walk us through what it is you want
Ok, i'm searching for yahoo Id's. But when u profile a yahoo id say http://profiles.yahoo.com/..angel.. That is not the way the name will look in chat. It will look like it does on the profile
.:[angel]:. I want it to find the .:[angel]:. in the html source and return it. to a list box or if i could just get it to where it would find a certain string period.
This is a small part of a program I wrote a while ago to grab stock prices from the internet and calculate my "net worth".
This sample requires that you drop a WebBrowser control onto a form (you need to Project\Components... and select Microsoft Internet Controls to get the WebBrowser control).
It simply navigates to a yahoo stocks page, grabs the HTML, and parses through it, looking for the Microsoft quote. Since the tags around the quote are always the same, I just use them as delimeters in my parsing. They are declared as contants at the top of the code.
Since the tags around the actual stock price on the web page are very common and appear all over the page (bold tags), I look for a unique tag first (the START_DELIM_SEARCH string). Then I search for PRICE_DELIM_1 from that point (I know that just after this will be the price), and then from this point I search for PRICE_DELIM_2 (this marks the end of the price). I grab the text between these delimeters (the price) and return it as a string.
You should be able to do something similar to grab items from another page, and then put them in a list box.
VB Code:
Option Explicit Private Const WEB_SITE_URL As String = "http://finance.yahoo.com/q?s=MSFT&d=v1" Private Const START_DELIM_SEARCH As String = "<A href=""/q?s=MSFT&d=t"">MSFT</A>" Private Const PRICE_DELIM_1 As String = "<b>" Private Const PRICE_DELIM_2 As String = "</b>" Private Sub Form_Load() WebBrowser1.Navigate (WEB_SITE_URL) End Sub Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) Dim sMSStockPrice As String sMSStockPrice = GetStockPrice(WebBrowser1.Document.documentElement.innerHTML) MsgBox "Current Microsoft Stock price: " & sMSStockPrice End Sub Private Function GetStockPrice(asHTML As String) As String Dim lsCurrText As String Dim lnStartPos As Integer Dim lnEndPos As Integer If Len(asHTML) > 0 Then lnStartPos = InStr(1, asHTML, START_DELIM_SEARCH) If lnStartPos > 0 Then lnStartPos = InStr(lnStartPos, asHTML, PRICE_DELIM_1, vbTextCompare) If lnStartPos > 0 Then lnStartPos = lnStartPos + Len(PRICE_DELIM_1) lnEndPos = InStr(lnStartPos, asHTML, PRICE_DELIM_2, vbTextCompare) If lnEndPos > 0 Then GetStockPrice = Mid(asHTML, lnStartPos, lnEndPos - lnStartPos) End If End If End If End If End Function