|
-
Jan 6th, 2003, 10:03 AM
#1
Thread Starter
Lively Member
Finding String of Html??
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??
 [vbcode]Private Sub Form_Load()
I would rather be hated for who I am than loved for who I'm not.[/vbcode]
End Sub
-
Jan 6th, 2003, 01:24 PM
#2
Thread Starter
Lively Member
 [vbcode]Private Sub Form_Load()
I would rather be hated for who I am than loved for who I'm not.[/vbcode]
End Sub
-
Jan 6th, 2003, 01:59 PM
#3
Fanatic Member
perhaps if we had a better idea of what is is you're trying to do.
walk us through what it is you want
It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.
-
Jan 6th, 2003, 02:05 PM
#4
Thread Starter
Lively Member
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.
 [vbcode]Private Sub Form_Load()
I would rather be hated for who I am than loved for who I'm not.[/vbcode]
End Sub
-
Jan 6th, 2003, 02:12 PM
#5
Frenzied Member
Here's an example of how to get text from a web page
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
Last edited by seaweed; Jan 6th, 2003 at 02:21 PM.
~seaweed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|