Results 1 to 5 of 5

Thread: Finding String of Html??

  1. #1

    Thread Starter
    Lively Member CagedConfession's Avatar
    Join Date
    Oct 2002
    Posts
    98

    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

  2. #2

    Thread Starter
    Lively Member CagedConfession's Avatar
    Join Date
    Oct 2002
    Posts
    98
    Anything??
    [vbcode]Private Sub Form_Load()
    I would rather be hated for who I am than loved for who I'm not.[/vbcode]
    End Sub

  3. #3
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    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.

  4. #4

    Thread Starter
    Lively Member CagedConfession's Avatar
    Join Date
    Oct 2002
    Posts
    98
    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

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    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:
    1. Option Explicit
    2.  
    3. Private Const WEB_SITE_URL As String = "http://finance.yahoo.com/q?s=MSFT&d=v1"
    4. Private Const START_DELIM_SEARCH As String = "<A href=""/q?s=MSFT&amp;d=t"">MSFT</A>"
    5. Private Const PRICE_DELIM_1 As String = "<b>"
    6. Private Const PRICE_DELIM_2 As String = "</b>"
    7.  
    8. Private Sub Form_Load()
    9.     WebBrowser1.Navigate (WEB_SITE_URL)
    10. End Sub
    11.  
    12. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    13.     Dim sMSStockPrice As String
    14.    
    15.     sMSStockPrice = GetStockPrice(WebBrowser1.Document.documentElement.innerHTML)
    16.    
    17.     MsgBox "Current Microsoft Stock price: " & sMSStockPrice
    18. End Sub
    19.  
    20. Private Function GetStockPrice(asHTML As String) As String
    21.     Dim lsCurrText As String
    22.     Dim lnStartPos As Integer
    23.     Dim lnEndPos As Integer
    24.    
    25.     If Len(asHTML) > 0 Then
    26.         lnStartPos = InStr(1, asHTML, START_DELIM_SEARCH)
    27.        
    28.         If lnStartPos > 0 Then
    29.             lnStartPos = InStr(lnStartPos, asHTML, PRICE_DELIM_1, vbTextCompare)
    30.            
    31.             If lnStartPos > 0 Then
    32.                 lnStartPos = lnStartPos + Len(PRICE_DELIM_1)
    33.                 lnEndPos = InStr(lnStartPos, asHTML, PRICE_DELIM_2, vbTextCompare)
    34.                
    35.                 If lnEndPos > 0 Then
    36.                     GetStockPrice = Mid(asHTML, lnStartPos, lnEndPos - lnStartPos)
    37.                 End If
    38.             End If
    39.         End If
    40.     End If
    41. 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
  •  



Click Here to Expand Forum to Full Width